Minor bug in Server-Side Auth for Next.js docs #26279
Labels
documentation
Improvements or additions to documentation
pr-opened
A PR has been opened to resolve the issue
Improve code snippet in documentation
Link
The code snippet under step 7 on this docs page
Describe the problem
TL;DR: When using GCP Cloud Run and Docker to deploy a NextJS app to production, the code snippet under step 7 redirects to the URL and port exposed by the docker container, instead of the external facing URL of the app.
Reproduce / see in action:
As you can see from the logs, the incoming GET request is coming from localhost:3000. It contains the search parameters. We are able to successfully extrac the JWT for the confirmation of the email address. Still, since/auth/confirm/route.ts is executed on the server side, we get redirected to localhost:3000, where docker is exposing the client, instead of the URL where the app is deployed.
Therefore
return NextResponse.redirect(redirectTo)
will redirect to localhost.Describe the improvement
The issue can simply be fixed by using redirect() from next/navigation.
Instead of
return NextResponse.redirect(redirectTo)
in line 26 we can useredirect(next)
after importingimport { redirect } from 'next/navigation'
See the proposed code snippet for auth/confirm/route.ts for step 7 of the docs page
This will redirect to the specified redirect URL or the global root of the deployed app, irrespective of the internal or external URL.
Additional context
Example code:
Example docker file:
Example logs:
The text was updated successfully, but these errors were encountered: