-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to encrypt sessionStorage using vuex-persistedstate? #57
Comments
import createPersistedState from 'vuex-persistedstate'
import SecureLS from 'secure-ls'
const ls = new SecureLS({
encodingType: 'rc4', // changeable
isCompression: false,
encryptionSecret: 's3cr3tPa$$w0rd@123', // change this
})
export default ({ store, req }) => {
createPersistedState({
key: 'TheGreatStore',
paths: [
'userStore.user', // Im using modules mode of vuex
],
storage: {
getItem: (key) => ls.get(key),
setItem: (key, value) => ls.set(key, value),
removeItem: (key) => ls.remove(key),
},
})(store)
} This is working in Nuxt Js at v2.15.3 with target static and SSR. Important for Nuxters, fetch() won't have the data from localstorage. You need to do something like that created() {
this.loading = true
},
beforeMount() {
this.$store.dispatch('fetchCoreDataAsync').then(() => {
this.someOtherMethodDependingOnLocalStorageItems()
this.loading = false
})
}, |
Hey @SuiKaSan , I refactored the code & tests have published a new version 2.0.0 You can refer this - https://github.com/softvar/secure-ls?tab=readme-ov-file#api-documentation
window.customSecureLsStore = {};
const storage = {
setItem: (key, value) => {
window.customSecureLsStore[key] = value || '';
},
getItem: (key) => {
return window.customSecureLsStore[key] || null;
},
removeItem: (key) => {
delete window.customSecureLsStore[key];
},
clear: () => {
window.customSecureLsStore = {};
},
};
const ls = new SecureLS({ encodingType: 'aes', isCompression: true, storage: storage }); I hope you will be glad to know this 🙌 |
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. I already issued this problem in the repository of vue-persistedstate. But they said this is scure-ls's issue. Anyone knows why? Please do tell.
The text was updated successfully, but these errors were encountered: