-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
Unable to use Nuxt with SSR and cookies #361
Comments
I see a couple of potential issues/solutions. Calling the store at the very root of your plugin makes it so the plugin might not be initialised yet (see #352), the store itself works because of how pinia can work outside of a Vue instance, but it will defer plugin initialisations. You can try calling For example : async function signInWithToken(newToken: string) {
// call composable here, I dont think there needs to be a `runWithContext` or such
const authStore = useAuthStore()
try {
authStore.token = newToken;
await refreshUser();
} catch (e) {
authStore.token = undefined;
authStore.refreshToken = undefined;
}
} This should make it work. Next version will also expose an explicit name for this plugin (originally called |
Hi, When does Pinia try to restore the cookies (what triggers it)? |
I will need a more complete reproduction to investigate, cause i cannot reproduce the error with what you sent in the original message. |
@jeanmatthieud I have fixed this a long time ago. Pr was not merged. Have a look at #99 Maybe this time @prazdevs may reconsider the PR since not only I have this issue. |
Are you using Nuxt?
Describe the bug
I have a Nuxt project, with pinia + pinia-plugin-persistedstate
I want to be able to use the cookies with SSR.
Pinia is used to store the auth token of the user, and refresh it if required.
I'm using the strore in a custom Nuxt plugin.
It works fine on the client side.
However, I realized that I have an issue if the server side tries to update the cookie through the Pinia store (eg. the new token is retrieve during SSR, and should be stored to the cookie to be transmitted to the client side).
Is it even possible?
I have the following issue when I try to update the store during SSR:
It is quite hard to write a reproduction, and it took me a lot of time to find the issue.
Reproduction
https://stackblitz.com/edit/nuxt-pinia-perstitedstate
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: