import { createStore, Store } from 'vuex';
import { State } from 'vue'
import user, { IUserInfoState } from './modules/user';
import global, { IGlobalState } from './modules/global';
import SecureLS from 'secure-ls'
import createPersistedState from 'vuex-persistedstate'
declare module '@vue/runtime-core' {
interface State {
user: IUserInfoState;
global: IGlobalState;
}
interface ComponentCustomProperties {
$store: Store<State>
}
}
const ls = new SecureLS({ isCompression: false })
window.sessionStorage.getItem = (key) => ls.get(key)
window.sessionStorage.setItem = (key, value) => ls.set(key, value)
window.sessionStorage.removeItem = (key) => ls.remove(key)
export default createStore<State>({
modules: {
user,
global,
},
plugins: [
createPersistedState({ storage: window.sessionStorage })
]
});
I want to encrypt the sessionStorage using secure-ls. But with the code above, the secure-ls only encrypted the localStorage. Anyone knows why? Please do tell.
vuex-persistedstate
version: 4.0.0node
version: 14.17.0npm
(oryarn
) version: 6.14.13secure-ls
version:1.2.6vue
version: 3.0.0vuex
version: 4.0.0Relevant code or config
I want to encrypt the sessionStorage using secure-ls. But with the code above, the secure-ls only encrypted the localStorage. Anyone knows why? Please do tell.