Redirecting the client to another page
Answered
Dovekie posted this in #help-forum
DovekieOP
1. Client makes a request to
2. Server reads the data, creates the user and then sends an email confirmation
3. I then want the client to be redirected to
My problem is that if I redirect the client, the request is a "POST" and not a "GET" that will show the client the confirm signup page.
Any ideas on how I could solve this ?
/api/auth/signup
with an email and password2. Server reads the data, creates the user and then sends an email confirmation
3. I then want the client to be redirected to
/auth/confirm-signup
My problem is that if I redirect the client, the request is a "POST" and not a "GET" that will show the client the confirm signup page.
Any ideas on how I could solve this ?
Answered by fuma π joulev
Correct, you can't redirect the user with a
fetch
on the client side. Use router.push
instead10 Replies
DovekieOP
Ideally I'd want the server redirecting the user to the
confirm-signup
page. But the only thing that comes to my mind is to have the client navigate to the page with a router.push
or somethingfuma π joulev
Correct, you can't redirect the user with a
fetch
on the client side. Use router.push
insteadAnswer
DovekieOP
I see, just to be 100% certain.
There's no way for me to redirect the user from the server to a "confirm-signup" page, right ?
I hope my question is clear
There's no way for me to redirect the user from the server to a "confirm-signup" page, right ?
I hope my question is clear
Here's how I want the flow to take place from the user's perspective:
1. I'm at
2. I type in my password, and email
3. I submit and make a request to
4. If my credentials are good, I want to see the
So, the redirect can only be performed by the client by using
1. I'm at
/auth/signup
2. I type in my password, and email
3. I submit and make a request to
/api/auth/signup
4. If my credentials are good, I want to see the
confirm-signup
screen. So I need to get redirected to itSo, the redirect can only be performed by the client by using
router.push()
or can the server somehow redirect me too ?fuma π joulev
True, unless the user directly open
/api/auth/signup
(if it is a GET
API endpoint), they won't get redirectedbecause that will be awful if opening a request can cause redirection on the client side
DovekieOP
Copy copy If there's any piece of documentation you suggest I read so I can get a better understanding of these mechanisms please let me know
Otherwise, thank you very much for your help
Otherwise, thank you very much for your help
fuma π joulev
Actually it's not related to Next.js, read this docs:
https://developer.mozilla.org/en-US/docs/Web/API/Request/redirect
https://developer.mozilla.org/en-US/docs/Web/API/Request/redirect
You can use
follow
in order to redirect the user, but that ignores client-side cache. With router.push
, you can reuse the cache, resulting a better performance during redirection.DovekieOP
I see, thank you again