Static GitHub Issues

[3114] Persisted state from VueX and NuxtJS

prev: 403 - In a weird way?
next: How to trigger error from the server manually?

Hi,

I use vuex-persistedstate package (https://github.com/robinvdvleuten/vuex-persistedstate) to persist data state on browser.

I use Adonuxt (a mix between NuxtJS and AdonisJS).

In VueX actions, I have this action:

nuxtClientInit ({commit}) {
      // I want get here state auth saved by persistedstate package
    }

This action is called by plugin:

localstorage.js

export default async (context) => {
  await context.store.dispatch('nuxtClientInit', context)
}

nuxt.js (config)

{
      src: '~/plugins/localstorage.js',
      ssr: false
    }

I want get state to configure Axios with the user token:

this.$axios.setToken(auth.jwt.token, 'Bearer')

I have the impression nuxtClientInit() is called before persistedstate package, so state.auth is null but it can observable in console:

image

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2694">#c2694</a>)</em></sub></div>