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

NEXTAUTH_URL gets strangely overwritten in next.config.js

Open osequi opened this issue 2 years ago • 5 comments

Environment

System:
    OS: Linux 5.4 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i5-7Y54 CPU @ 1.20GHz
    Memory: 661.49 MB / 7.64 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.18.3 - ~/.nvm/versions/node/v14.18.3/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.18.3/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Brave Browser: 102.1.39.122
    Chromium: 103.0.5060.53
    Firefox: 101.0.1
  npmPackages:
    next: latest => 12.1.0 
    next-auth: ^4.3.1 => 4.3.1 
    react: ^17.0.2 => 17.0.2 

Reproduction URL

na

Describe the issue

I have

# env.development.local
NEXTAUTH_URL=http://localhost:3000

and

// next.config.js
module.exports = {
  env: {
    NEXTAUTH_URL: "http://example.com/overwritten-in-nextconfig/",
  },
};

When running the app I'm getting:

175557400-634f92cf-3a16-49db-bc91-7f60248bf2ce

How to reproduce

In a plain simple NextAuth app add these two files env.development.local and next.config.js with the content from the above examples.

Expected behavior

The NEXTAUTH_URL should be http://example.com/overwritten-in-nextconfig/ vs. http://localhost:3000/overwritten-in-nextconfig/

osequi avatar Jun 24 '22 14:06 osequi

Note when adding the https://example.com/custom-route/api/auth url from https://next-auth.js.org/configuration/options#nextauth_url I'm getting the same error:

image

osequi avatar Jun 24 '22 15:06 osequi

Hi @osequi , I've proposed a workaround here : https://github.com/nextauthjs/next-auth/issues/4748 Hopping it could help you,

fonzarely avatar Jun 27 '22 12:06 fonzarely

It seems NEXTAUTH_URL can be only set in .env files: https://github.com/nextauthjs/next-auth/issues/1505#issuecomment-797660838

osequi avatar Jun 28 '22 10:06 osequi

This should only be set in environment variables, but when does next.config.js runs to overwrite it?

agrittiwari avatar Jul 26 '22 07:07 agrittiwari

I took my inspiration from this post to manage my variables setting in next.config.js You are reading environment variables the wrong way in Next.js . This make the lint, build and run to fail if an env variable is missing.

fonzarely avatar Aug 04 '22 12:08 fonzarely