question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

conflict in using @nuxtjs/auth

See original GitHub issue

how to use vuex-persist and @nuxtjs/auth I can’t login when I implement nuxt plugin

import VuexPersistence from 'vuex-persist'

export default ({ store }) => {
  window.onNuxtReady(() => {
    new VuexPersistence({
      /* your options */
      modules: ['account']
    }).plugin(store)
  })
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

4reactions
anandkkprcommented, Apr 27, 2020

Still some issues with Auth module

use this

// ~/store/index.js
import VuexPersistence from 'vuex-persist'
const vuexLocal = new VuexPersistence({
  storage: window.localStorage
})

export const plugins = [vuexLocal.plugin]

instead of this in the documentation

// Inside - nuxt.config.js
export default {
  plugins: [
    { src: '~/plugins/vuex-persist', ssr: false }
  ]
}
// ~/plugins/vuex-persist.js
import VuexPersistence from 'vuex-persist'
 
export default ({ store }) => {
  window.onNuxtReady(() => {
    new VuexPersistence({
    /* your options */
    }).plugin(store);
  });
}

Thank you SO MUCH for this @PRAJINPRAKASH !!! This was a life saver!!!

In order to get things working on my end, I followed your instructions and did the following:

in /nuxt.config.js, I made the following edit:

from

  plugins: [
    '@plugins/vue-inject-uuid',
    '@plugins/vue-inject-lodash',
    '@plugins/vue-inject-authUtils',
    '@plugins/vuetify-datetime-picker',
    {src: '@/plugins/vuex-persist', mode: 'client'},
  ],

to (removed the Vuex Persist plugin that the Vuex-Persist doc says we need to have)

  plugins: [
    '@plugins/vue-inject-uuid',
    '@plugins/vue-inject-lodash',
    '@plugins/vue-inject-authUtils',
    '@plugins/vuetify-datetime-picker',
  ],

then… I deleted the plugin file - /plugins/vuex-persist.js - which, for posterity’s sake had the following code in it:

/**
 * @see https://github.com/championswimmer/vuex-persist#tips-for-nuxt
 */
import VuexPersistence from 'vuex-persist';

export default ({store}) => {
  if (process.browser) {
    window.onNuxtReady(() => {
      new VuexPersistence({
        strictMode: process.env.NODE_ENV !== 'production',
        storage: localStorage,
      }).plugin(store);
    });
  }
};

Finally, I updated my root Store file with @PRAJINPRAKASH’s suggestion - but also needed to ensure the Vue-Persist RESTORE_MUTATION mutation is declared as well - else Vuex-Persist will be unable to restore the state from on page reload.

In the root Store file at /store/index.js:

import VuexPersistence from 'vuex-persist';

const vuexPersist = new VuexPersistence({
  strictMode: process.env.NODE_ENV !== 'production',
  storage: window.localStorage,
});

export const mutations = {
  RESTORE_MUTATION: vuexPersist.RESTORE_MUTATION,
};

export const plugins = [vuexPersist.plugin];

So, with just the above file, I’ve finally got Vuex-Persist working with Nuxt.js with Nuxt Auth module turned on and working AND, the main reason why I was having so many issues - that, if you are logged out then refresh your login page (as configured in nuxt.config.js in the auth module’s redirect options) and then try to login, upon successful login, the page would not redirect to the next page - regardless of whether you set the auth.redirect.home option in nuxt.config.js or, if you use this.$auth.loginWith('local',...).then(()=>{ this.$router.push('/'); });, neither option worked.

The above has finally fixed things, what a relief - and the end of some 5 days of debugging!

EDIT:

As far as this Issue is concerned, I think it would be great if the Vuex-Persist documentation could benefit from being updated so that the section for use with Nuxt explains what to do if a project uses Nuxt Auth.

I’d also really like to understand what the problem was/is - @PRAJINPRAKASH, could you please explain why the existing documentation causes this issue if you’re able to?

Thanks everyone!

4reactions
PRAJINPRAKASHcommented, Apr 12, 2020

Still some issues with Auth module

use this

// ~/store/index.js
import VuexPersistence from 'vuex-persist'
const vuexLocal = new VuexPersistence({
  storage: window.localStorage
})

export const plugins = [vuexLocal.plugin]

instead of this in the documentation

// Inside - nuxt.config.js
export default {
  plugins: [
    { src: '~/plugins/vuex-persist', ssr: false }
  ]
}
// ~/plugins/vuex-persist.js
import VuexPersistence from 'vuex-persist'
 
export default ({ store }) => {
  window.onNuxtReady(() => {
    new VuexPersistence({
    /* your options */
    }).plugin(store);
  });
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuxtjs auth module - token endpoint in auth strategies ...
Is John 2:23-25 there to tell us that Jesus' conflict with the Jewish leaders wasn't a Jewish problem but a human problem? How...
Read more >
Authentication in Nuxt app - BlowStack
First install the official authentication module for Nuxt. npm i @nuxtjs/auth. COPY. After installation add auth module to the nuxt config.
Read more >
@nuxtjs/auth - Awesome JS
This helps to prevent application crashing with auth module. (b58ca17); resetOnError is set to false by default. Previously any network error was causing ......
Read more >
How to configure Okta to work with Nuxtjs Auth Module?
Hi there, I'm struggling on configuring my Okta App credentials with my NuxtJS app. I read this article from Andy March ...
Read more >
@nuxtjs/firebase social auth - DEV Community ‍ ‍
Tagged with nuxt, firebase, auth. ... worker in dev environment to avoid conflicts with HMR // only set this true for testing and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found