auth0 / nextjs-auth0

Next.js SDK for signing in with Auth0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong redirect URL on production

bvaughn opened this issue · comments

Checklist

Description

I followed the auth0 instructions which recommend configuring the .env.production file like so:

NEXT_PUBLIC_AUTH0_BASE_URL=$VERCEL_URL

The Vercel documentation says the following about the VERCEL_URL variable (emphasis mine):

The domain name of the generated deployment URL. Example: *.vercel.app.

Combining the above means that auth works fine on preview deployments (generated URLs) but when I try to use my vanity URL, sign-in fails because of a bad/mismatching redirect_uri.

For example, let's say that my production URL is example.vercel.app. When I try to sign in, the AUTH0_BASE_URL is causing the redirect_uri to get set to a generated deployment URL like example-auj9zcz7f-myorg.vercel.app, which then fails.

Any suggestions?

Reproduction

  1. Follow the guide in https://vercel.com/docs/projects/environment-variables/system-environment-variables

Additional context

No response

nextjs-auth0 version

3.5.0

Next.js version

14.1.0

Node.js version

N/A

I read a lot of docs and GitHub issues and eventually found my way to the note at the bottom of this page:
https://github.com/auth0/nextjs-auth0/blob/main/example-app/README.md#production-deployments-or-other-environments-with-fixed-urls

So I set a production only environment variable in NextJS for AUTH0_BASE_URL that has the value of my vanity URL and redeployed and that fixed the login issue.