next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

NEXTAUTH_URL is seen as undefined if set via next.config.js

Open fonzarely opened this issue 2 years ago • 0 comments

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.

fonzarely avatar Jun 22 '22 09:06 fonzarely