Next.js Discord

Discord Forum

Redirect after login doesn't work

Answered
Dreamgineer posted this in #help-forum
Open in Discord
I have a parallel route setup for my /login which after logging in, does router.push("/dash"). Now the problem is when you visit the website, there is a link that preloads /dash so it gets redirected to /login and thus preloads that. So when router.push pushes to /dash it cached the redirect and wouldn't go anywhere. Is there a way to fix it?
Answered by Dreamgineer
View full answer

8 Replies

does visiting the route manually works?
yes, because that's not prefetched by client side nav
I just want router.push to not use the stale redirect from before login
Original message was deleted
Answer
just use server actions for login with revalidatePath and redirect, as that will clear client cache and also return the dash in one go (or the error object if user/password not correct)
that was also suggested but I didn't want to spam this channel with 5 forwarded messages
ah cool
(its a better method for your usecase tho imo)