Closed o1lab closed 6 years ago
This sounds like a specific use-case for your project's setup. Unfortunately, I do not have the time to dive into such questions. Please go to StackOverflow or spectrum.chat to look for help.
For those who come across this problem - as a workaround I have now a middleware which checks the user state in store. If it is null then it makes an api call to get data from express-server and commit it to store. This way any data in request object can be persisted to vuex-persistedstate
middleware/auth.js
export default async function ({context, store, route, redirect, req}) {
if (process.client && store.getters.User === null) {
console.log('Middleware in in client, user data is null: get user data');
let user = await store.$axios.get('/users/me');
if (user && user.data ) {
store.commit('SET_USER', user.data);
}
}
}
I have a similar problem just like you. I guess the problem may because, when I refresh the page, vue deletes store in vuex and middleware is loaded before vue persist sets values to vuex.
Using latest version : 2.5.1
Is there a way to access request object in vuex-persistedstate plugin function.
Im building social authorization in nuxt and on successfull authorization from express - the user object is stored in request. And this user object has to be committed to store and to localstorage.
nuxt.config.js
{ src: '~plugins/localStorage.js', ssr: false },
middleware/localStorage.js