Search code examples
javascriptvue.jslocal-storagevuexnuxt.js

Is the any comparability issue with nuxt Auth Module and vuex-persist?


Is there any compatible issue with nuxt Auth module and vuex-persist ?

I was added vuex-persist like this.

// 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);
  });
}

But it fails to work.

  1. When i click login it perform previous action(login with google/other previously clicked).
  2. When logged in the status fails to persists.

Any solution for this?


Solution

  • Yes there was some issues with @nuxtjs/auth module and vuex-persist ,

    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);
      });
    }
    

    or you can use vuex-persistedstate as an alternative.