Important to use pinia correctly on SSR - State leaking between concurrent sessions when useStore comes after an await etc #2158
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We have encountered this a few times, and I think really it's important to know about because it's hard to test and and an easy mistake to make. It can easily leak user data if not handled correctly.
We need some feedback on how to to solve passing the pinia instance all the way to the API-functions in the example
Reproduction link
https://github.com/iPrytz/vue3-pinia-ssr-example
Steps to reproduce
userStore
andmyDataStore
useUserStore().sessionId
useUserStore().sessionId
againconst store = useUserStore()
andstore.sessionId
is used both before and after await, but in more complex cases it can still be a missmatch.For example, in our store, we fetch specific user data connected to the sessionId, but before we do that we need to fetch and await the users profile settings, then we can fetch the specific user data. From our store we call the API and in the API-handler we then add the sessionId/token from userStore, and now we have a missmatch because we do
useUserStore()
after theawait user profile
while we have multipe requests comming in to our node server. So the sessionId/token added to the request is now from another user and we get mixed up data.I added a repo to reproduce the problem, instructions how to test this is found in the README
Would also love to get some explanation on what is actually hapening here that is causing this behavior.
Thank you to everyone working on this project, you're awesome!! 💯 🙌
Beta Was this translation helpful? Give feedback.
All reactions