Krd8ssb
data not persisting between updating store value and a navigateTo redirect
I'm working on my first nuxt app and am running into an issue with pinia updating properly before I use navigateTo for a redirect.
Use case:
I have my app receiving a callback as part of the auth flow from WorkOS (My app has SSR enabled and persisted state is using cookies).
Once a user authenticates with their google account (or email/password) via WorkOS, it sends the auth code to my app
/callback?code={some-auth-code}
From there, I send that auth code to my API which will send it to WorkOS in exchange for the user's session token and user object.
I then store the session token in a cookie (this works). on the next line, I update the authStore loggedIn property to true. If I do not redirect from the /callback to another page, the store is updated successfully. If I redirect using navigateTo('/) (or whatever value is in my referrer store), the loggedIn state is never updated.
I'm using the following packages/versions
I've been able to trace the following:
- App successfully exchanges the code for session token
- SSR updates the authStore.loggedIn value as true.
- If I use navigateTo('/') after setting loggedIn = true, state is never updated.
- If I wait until CSR is complete, store is updated and persisted successfully.
I'm also experiencing my useFetch call making a request on SSR & CSR, to which the CSR received an error since the auth code was already exchanged when the SSR used useFetch to perform the initial call
I feel like I just need to know when the store is updated then issue the redirect but can't seem to figure it out 🤦♂️3 replies