nextauthjs / nextauthjs/next-auth
NEXTAUTH_URL is seen as undefined if set via next.config.js
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
Environment
System:
OS: macOS 12.4
CPU: (10) arm64 Apple M1 Pro
Memory: 1.75 GB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
Browsers:
Chrome: 102.0.5005.115
Firefox: 101.0.1
Safari: 15.5
npmPackages:
next: ^12.1.6 => 12.1.6
next-auth: ^4.3.4 => 4.3.4
react: ^17.0.2 => 17.0.2
Reproduction URL
https://github.com/ArtPoint-fr/next-auth-env-var-issue
Describe the issue
What
Already using APP_URL as env variable we did map this env variable via next.config.js
When starting the app we have 'NEXTAUTH_URL' logs witch seems to be the missing env var warning from next-auth.
And any redirect point to localhost:3000 as if the app is working on Vercel.
why
We are managing our env variables this way so any missing variable makes next to fail at build, start, test and lint.
workaround
- Create the NEXTAUTH_URL as env variable of the next process.
- map the env variable in next.config.js any way so that we can catch the missing variable.
How to reproduce
- Set env variables in your .env.local (APP_URL, NEXTAUTH_SECRET, GOOGLE_ID, GOOGLE_SECRET)
- APP_URL takes place of NEXTAUTH_URL since it is mapped in next.config.js
yarn dev- login with google auth
- check the logs and see NEXTAUTH_URL warnings
fab@xxx next-auth-env-var-issue % yarn dev
yarn run v1.22.19
$ next
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info - Loaded env from /Users/fab/TMP/next-auth-env-var-issue/.env.local
###############################################################
isDev:true isProd:false isStaging:false
###############################################################
wait - compiling...
event - compiled client and server successfully in 240 ms (160 modules)
wait - compiling /api/auth/[...nextauth]...
wait - compiling...
event - compiled client and server successfully in 52 ms (175 modules)
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
wait - compiling / (client and server)...
wait - compiling...
event - compiled client and server successfully in 80 ms (218 modules)
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
Expected behavior
- NEXTAUTH_URL should be provided via next.config.js
- next-auth should explicitly log the issue when NEXTAUTH_URL & VERCEL variables are missing.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review next.config.js and the /api/auth/[...nextauth] entry point, then reproduce the issue with .env.local and yarn dev. Check how the mapped APP_URL reaches the auth route and compare the warning and redirect behavior with the expected NEXTAUTH_URL handling. Done means the configured URL is recognized and missing NEXTAUTH_URL or VERCEL variables are reported explicitly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nextjs, typescript
- Domain
- authentication
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100