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 ?
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.
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({ // ...
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.
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,
})],
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With