I need use vuex-persistedstate to my project, but first of all I need to set SSR equals false so I can running the project, but this error occurs: window is not defined
. Probably because it is trying to access localstorage, then Javascript use window.localstorage
, but it can't access because the only way to do that is just running the code in client side.
this is my store:
// persistedState.js
import Vuex from "vuex"
import createPersistedState from "vuex-persistedstate"
const store = new Vuex.Store({
state: {
token: null,
},
getters: {
isAuthenticated(state) {
return state.token !== null
},
},
mutations: {
setToken(state, token) {
state.token = token
},
},
plugins: [createPersistedState()],
})
export default store
and my plguins
// nuxt.config.js
plugins: [
"@/plugins/chart.js",
{ src: "@/plugins/persistedState.js", ssr: false },
],
look that even I setting ssr equals false, it doesnt work
detail: I'm trying using it in my middleware