Next.js Discord

Discord Forum

Router redirect cache

Answered
Masai Lion posted this in #help-forum
Open in Discord
Avatar
Masai LionOP
When accessing the "/" page: my middleware.ts redirects the user to the "/login" page if he does not have a token in his cookies.

On the "/login" page, a token is added to the cookies and the user is redirected to the "/" page, using router.refresh(), followed by router.push("/").

The problem is that this redirection is not happening, it seems that the next one keeps a cache of the first redirection. The expected behavior only happens when pressing F5 on the page.
Answered by Masai Lion
Solved adding 303 status in the redirect
View full answer

4 Replies

Avatar
why don't you set the cookies inside the middleware?
Avatar
Masai LionOP
The user only obtains the token after logging in.
Isn't there a way to clear the client cache? Forcing him to pass the middleware again, but now with the token in his cookies?
Avatar
Masai LionOP
Solved adding 303 status in the redirect
Answer