State doesn't seem to be persisted using Nuxt 2 and `secure-ls` package
theolavaux opened this issue · 0 comments
theolavaux commented
Describe the bug
I'm using Nuxt 2 and I would like to persist my state using the secure-ls
package.
If I put log in getItem
, setItem
or removeItem
, none seems to be called.
And my state is not persisted after a page refresh for instance.
To Reproduce
Reproduction link
Steps to reproduce the behavior:
- Create a Nuxt 2 project.
- Implement basic Pinia state.
- Install
pinia-plugin-persistedstate2
. - Create a file named
pinia.client.ts
with the following content.
import { Plugin } from '@nuxt/types';
import { createPersistedStatePlugin } from 'pinia-plugin-persistedstate-2';
import SecureLS from 'secure-ls';
const piniaPersistedStatePlugin = () => {
const ls = new SecureLS({ isCompression: false });
createPersistedStatePlugin({
storage: {
getItem: (key) => ls.get(key),
setItem: (key, value) => ls.set(key, value),
removeItem: (key) => ls.remove(key),
},
});
};
const piniaPlugin: Plugin = ({ $pinia }) => {
$pinia.use(piniaPersistedStatePlugin);
};
export default piniaPlugin;
Expected behavior
State is persisted