Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuex persisted state doesn't remove state after closing tab

I use vuex-persistedstate package https://github.com/robinvdvleuten/vuex-persistedstate to persist data state on browser.

When I logout from the app, the package clears all the state info about the authenticated user. However, I realized that, it doesn't remove the sensitive data after closing the tab and the jwt token expires, and it is still reachable on the local storage.

Any recommendation to handle this ?

like image 854
DuyguKeskek Avatar asked Oct 01 '18 13:10

DuyguKeskek


People also ask

How do I clear my vuex persisted state?

There is no way to delete the persisted state programmatically, there are use cases for removing the state in local storage. If the current behavior is a bug, please provide the steps to reproduce. What is the expected behavior? We should be able to remove the state from local storage either with localStorage.

Does vuex state persist on refresh?

To persist Vuex state on page refresh, we can use the vuex-persistedstate package. import { Store } from "vuex"; import createPersistedState from "vuex-persistedstate"; import * as Cookies from "js-cookie"; const store = new Store({ // ...

What is the use of Mapstate in vuex?

Mapping in Vuex enables you to bind any of the state's properties, like getters, mutations, actions, or state, to a computed property in a component and use data directly from the state. Although we can get the job done with this. $store.state.user.data.name , we can use a map helper to simplify it to this.


1 Answers

If you want to store data for the lifetime of the current tab only, you need to store data inside the sessionStorage instead of inside the localStorage. vuex-persistedstate makes this easy for you.

When you create an instance of this plugin, you can specify an options object, and this object can have a link to the sessionStorage, if you want to use that instead.

import createPersistedState from 'vuex-persistedstate'

const store = new Vuex.Store({
    // ...
    plugins: [createPersistedState({
        storage: window.sessionStorage,
    })],
})
like image 84
Ferrybig Avatar answered Oct 01 '22 13:10

Ferrybig