I am making an application in nuxt.js, I use a store to store data including the user who connects and I want to keep the user's connection elements in the localStorage. So to do this I used a plugin which is vuex-persist of which here is the code.
Here is my store/login.js :
export const state = () => ({
user: ''
})
export const mutations = {
setUser(state, newUser) {
state.user = newUser;
}
}
export const getters = {
getUser(state) {
return state.user
}
}
Here is my plugin/vuex-persist.js :
import VuexPersistence from 'vuex-persist';
export default ({ store }) => {
window.onNuxtReady(() => {
new VuexPersistence({
key: "vuex",
storage: window.localStorage,
reducer: state => ({ login: state.login }),
}).plugin(store);
});
};
So this saves the user in localStorage, for example:
But when I refresh the page or when I open a new page in a new tab I have to reconnect all the time.
I don't understand why because when I don't put a reducer function in my plugin I don't need to constantly reconnect but the problem is that it doesn't just save the user in localStorage.
Thanks for your help
