#Auth with simple token and bearer

10 messages · Page 1 of 1 (latest)

naive dome
#

I have simple pinia store for auth and a middleware to verify if the user is logged in. But, the middleware dosen't work when I refresh the page.
the code goes here: https://pastebin.com/n16hfNab
What can I do to store the token, in nuxt2 I used localStoare. But it seems dosen't work in pinia. I am using SSR.

tawdry magnet
#

for SSR u need cookies since u cannot access localStorage on server

#

I would suggest to validate user inside a plugin for page init

#

and middleware for page redirects

pure anchor
#

I also suspect that SSR is causing your issues here. See if switching off SSR (for that route) solves your problems. SSR probably doesn't make sense for auth-guarded routes anyway...

naive dome
#

The project should be on SSR for SEO purposes. Is there any example for my situation? Thanks

tawdry magnet
#

This is my old article for Nuxt 2

#

I can write for Nuxt 3 as well

#

but it should be pretty much similar. Difference is with nuxtServerInit in Nuxt 3. Instead of that from nuxt 2 you can use Plugin for that one