Closed notjasonknott closed 3 years ago
The issue it's confusing, but I think that I understand fine.
You are using vuex-webextensions with persistent states in your config for auth things, but beforeEnter logic it's executed before localstorage data read.
Unafortunally, the local storage read are async and have a bit of delay on initialization, so you should wait for this initialization before do any action that require saved states on it.
To workarround this situations, I implemented the VWE_ReplaceState
mutation on https://github.com/MitsuhaKitsune/vuex-webextensions/commit/42744059bf86ceaf72d599a3f1e222f30e8105c1 and you can hook this mutation to do your initialization logics ensuring that data are fully loaded.
I gona close the issue because isn't it as it has explained, but I gona document the wait for VWE_ReplaceState
mutation before do any action that require states stored on localstorage.
If I didn't understand fine, just tell me and I reopen this, but I think that the problem are there.
I'm trying to access
store.getters.user.token
to check if there is an active user state. If there is, I want to redirect the user to the app, but if there isn't then they need to log in.routes.ts
In this context,
store.getters.user.token
is undefined because theuser
object looks like this:Whereas, in any *.vue file, the
store.getters.user.token
reveals the token:Home.vue
Home.vue showing the token:![image](https://user-images.githubusercontent.com/28274424/88569412-f82f6380-d014-11ea-97b0-5d1efa2627bf.png)
But, when I![image](https://user-images.githubusercontent.com/28274424/88569775-81469a80-d015-11ea-9488-a8a6d2583ee8.png)
console.log(store.state)
in routes.ts I get the user object containing all the right values!My hypothesis is that it has something to do with the object being loaded asynchronously, but I am not sure how to fix that issue. Do you have any ideas for what I could do?
Update I am currently using a setTimeout to fix this issue. If someone could think of a more ideal solution, I'm all ears!