1👍
✅
The problem is that your getters are returning an attribute of localStorage which isn’t reactive. So you need to set localStorage data in your store, so that your getters know when its been updated.
state: {
user: {
name: null,
accessLevel: -1
},
jwt : null,
},
mutations: {
setAdminJwt: (state, payload) => {
state.jwt = payload
},
setLoggedAdmin: (state, payload) => {
state.user.name = payload.name
state.user.accessLevel = payload.accessLevel
}
},
getters: {
getAdminJwt: () => {
return state.jwt;
},
getLoggedAdmin: (state) => {
return state.user
}
},
You don’t need to use getters for the above. You can call store.state.user
directly from your beforeEach function.
Source:stackexchange.com