N
Nuxt2y ago
bnason

useState and redirection losing value

I'm using useState within my auth plugin and during the SSR, it redirects to the login page if they are not authenticated. It's also capturing the current path and saves it in a useState ref, however, when the redirect happens, it's doing an HTTP redirect, which basically creates a new request to the server which seems to re-call the ssr and that re-runs the plugin but this time it doesn't know about the previous requests path. Does anyone have any suggestions?
1 Reply
bnason
bnasonOP2y ago
The only workaround I can think of is, during the redirect, append the current path as a query param and then look to that as well when the plugin inits That is what I ended up doing. Not sure if there is a better/official way though
Want results from more Discord servers?
Add your server