Router redirect cache
Answered
Masai Lion posted this in #help-forum
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.
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.
4 Replies
why don't you set the cookies inside the middleware?
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?
Masai LionOP
Solved adding 303 status in the redirect
Answer