Understanding redirect after refresh without token and how to prevent it? #1664
Unanswered
gustavonikov
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Guys, this is the context for my doubt: I removed authentication by token and I'm trying to do it via httpOnly cookie via SSR.
When a user tries to login, I get the token directly from api response and set the token for Authorization header on axios, making the user authenticated to make requests after.
After the login, my plan was when I refresh the page and probably lose the token, get the token from the httponly cookie that I set from the backend, passing it into the headers again.
But, if I refresh the page automatically redirects me to '/' (attachment). I guess that this redirect is made in the SSR.
So finally finishing the context, my problem is: how can I intercept this redirect before it happens?
To get the cookie and set to headers and make all that I need to stay the user logged.
I did take a look at Nuxt docs and I see two possible ways:
Make a server middleware: https://nuxtjs.org/docs/configuration-glossary/configuration-servermiddleware/
Use nuxtServerInit: https://nuxtjs.org/docs/directory-structure/store#the-nuxtserverinit-action
But, I don't know if they are correct ways to do it. Someone had this problem or know how to solve it?
Or even can confirm if one of the two options that I writed above can work?
Beta Was this translation helpful? Give feedback.
All reactions