pinia-plugin-persistedstate
pinia-plugin-persistedstate copied to clipboard
[nuxt] Feature request: client only storage on some stores only
Describe the bug
I would like to have an option to declare some stores to use localstorage while using my global storage is using cache. I am currently using nuxt and it is registered as a plugin that runs both on server and client.
Changing
persist: {
key: 'user',
storage: localStorage,
},
Causes an error about localstorage not available. And it's the right error because when rendered server side, there's no localstorage available.
So for the meantime I just do,
Usually works but when it doesn't work, it resets to the initial state of the store.
Reproduction
Install @pinia/nuxt 0.3.1 together with pinia 2.0.17
System Info
System:
OS: macOS 12.3
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 25.35 GB / 64.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 18.7.0 - /usr/local/bin/node
Yarn: 3.2.1 - /usr/local/bin/yarn
npm: 8.15.0 - /usr/local/bin/npm
Browsers:
Chrome: 104.0.5112.79
Firefox: 103.0
Safari: 15.4
Used Package Manager
yarn
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guide.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] The provided reproduction is a minimal reproducible of the bug.
Let cache turn into storage-like with unjs/unstorage?
ooooh unstorage seems like a very very interesting option to consider, not only for this issue
It is indeed very interesting. But since it's asynchronous, I'm not really sure how reliable it will be inside plugins and middlewares
v3 is now release with available nuxt module as well! docs are also deployed 🚀 you can use localstorage in some stores and cookies in others :) closing this for now, if still having issues, feel free to reopen