State doesn't seem to be persisted using Nuxt 2 and secure-ls
package
#17
-
Describe the bug To Reproduce Steps to reproduce the behavior:
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 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
The - const piniaPersistedStatePlugin = () => {
+ const piniaPersistedStatePlugin = (context) => {
const ls = new SecureLS({ isCompression: false });
- createPersistedStatePlugin(/* ... */);
+ const install = createPersistedStatePlugin(/* ... */);
+ install(context);
}; |
Beta Was this translation helpful? Give feedback.
-
Awesome! It works now, only one problem left: if I clear the |
Beta Was this translation helpful? Give feedback.
-
I found the culprit! I went into the debugger and in my case here the |
Beta Was this translation helpful? Give feedback.
The
createPersistedStatePlugin
function will return an install function, we need to register it: