Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referencing NEXTAUTH_URL in app router causes build error for runtime environment variables #9212

Closed
c-kirkeby opened this issue Nov 22, 2023 · 3 comments
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@c-kirkeby
Copy link

c-kirkeby commented Nov 22, 2023

Environment

(From CodeSandbox)
System:
OS: Linux 6.1 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
CPU: (2) x64 AMD EPYC
Memory: 400.73 MB / 2.01 GB
Container: Yes
Shell: 5.8 - /bin/zsh
Binaries:
Node: 20.9.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.8.1 - /usr/local/bin/npm
pnpm: 8.10.2 - /usr/local/share/npm-global/bin/pnpm
npmPackages:
next: latest => 14.0.3
next-auth: beta => 5.0.0-beta.3
react: ^18.2.0 => 18.2.0

Reproduction URL

https://github.com/c-kirkeby/next-auth-example

Describe the issue

Referencing NEXTAUTH_URL in the app directory causes builds to fail if NEXTAUTH_URL is not available at compile time. This is causing issues in CI when we build a docker image that uses environment variables at runtime. I've modified the next-auth-example to use the cookies option in the auth config. In attempting to figure out how to make this work I've put unsable_noStore() and export dynamic = 'force-dynamic' in just about every page and it still doesn't work.

The GitHub bot was unhappy when I linked to Codesandbox last time so I've added the attached repo instead but the link to Codesandbox is here.

How to reproduce

Open the CodeSandbox and npm run build. Do not set any environment variables for the build as they should be defined at runtime.

Expected behavior

As far as I understand, next-auth shouldn't be trying to access the environment variables at build time if we opt into dynamic rendering.

@c-kirkeby c-kirkeby added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Nov 22, 2023
@balazsorban44
Copy link
Member

This makes sense and is expected. Some routes might be rendered at build time, so this variable needs to be present then as well. FWIW, this variable is rarely needed anymore, what's the use case?

@c-kirkeby
Copy link
Author

For our particular use case we're sharing a secure cookie to have a persisted session token across our subdomains such as this approach here. This works so long as we use the page router, but if we try to migrate to the app router we get an error at build time.

@balazsorban44
Copy link
Member

balazsorban44 commented Jan 25, 2024

This can be addressed, as lazy initialization (prev. advanced initialization) is now supported in v5 too. see #9638

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

2 participants