Next.js Discord

Discord Forum

Server side redirects after login

Answered
Dovekie posted this in #help-forum
Open in Discord
DovekieOP
I have a NextJS 13 app on which I've implemented auth.

I have an API route /login that's called by the client with a POST request (with a username and password). It implements the necessary auth logic and then sends a response by setting the client's headers to the auth tokens.

Then, if the response is successful, the client app redirects itself to the / route.

I'm wondering if the server could also redirect the client, taking away any responsibility during auth.
Answered by joulev
you can do this but only with server actions - then you can use redirect to redirect the user away. regular route handlers cannot achieve this.
View full answer

2 Replies