Wait for Session storage data before anything else in Nuxt #3053
Unanswered
Bartas139
asked this question in
Help and Questions
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.
-
Hi, can someone please help me with my issue. I have a nuxt4 app where I store auth info in pinia session persist storage like this:
This works well until I hard refresh the page in browser, in that case I came to weird behaviour, which is probably (I tested a lot) caused by my authMiddleware logic and the way pinia needs to extract the data from session storage first. The process and problem:
The middleware:
This should be ok for me, there is just insta redirect to signin and back to desired page, but here comes the problem. I use some userData in my Nuxt layout and this middleware redirect causes that Nuxt layout is not changed properly from unloged to default, so I see content of /dashboard, but with unloged layout. (and some hydratation missmatches):
(This missmatch is not there, when I navigate "organicly" so I am on signin, press SignIn button and I am send to /dashboard a "normal" way)
I realy dont know why this happens, but when I turn off that middleware everything works well.
What I wanted to do is to wait until all storages are ready (for example display some global loader) and when they are ready display the desired page, so there is not the redirect from /dashboard to /signin and back, but my attempts always failed.
Is there any clear solution, or am I missing something else, what causes the problem?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions