Why is next-auth redirect preventing Nextjs from updating the url when redirecting on login
Unanswered
Masai Lion posted this in #help-forum
Masai LionOP
Here's what i am going through:
I submit the sign in form
the signIn server action from next-auth is redirecting to '/'
importantly: at this point, the router has already received a response from the server, indicating it's on the '/' page.
Next.js will fire off an intra-app request to '/' since that's what the redirect told it to do, but because the user is now authenticated, but in my middleware i call a redirect to instead forward the request to '/protected'
The signIn request to '/' returns the page data for '/protected', hence the UI updating, but not the URL.
How can i fix this?
I submit the sign in form
the signIn server action from next-auth is redirecting to '/'
importantly: at this point, the router has already received a response from the server, indicating it's on the '/' page.
Next.js will fire off an intra-app request to '/' since that's what the redirect told it to do, but because the user is now authenticated, but in my middleware i call a redirect to instead forward the request to '/protected'
The signIn request to '/' returns the page data for '/protected', hence the UI updating, but not the URL.
How can i fix this?
4 Replies
Masai LionOP
Is this issue peculiar to my use case or what?
West African Crocodile
if you don't use group route, your url must be changed by redirect or router.push.
Masai LionOP
So the issue is the group route, cos’ I’m using it. Any idea how can get this to work?
West African Crocodile
okay, ofc, group route is very useful if you wanna hidden your real url.
but during the implement process, you have many problems.
So in many case, I don't use group route.
if you wanna protect your page, you can use default route - /protect/dashboard, /protect/settings.....
but during the implement process, you have many problems.
So in many case, I don't use group route.
if you wanna protect your page, you can use default route - /protect/dashboard, /protect/settings.....