Skip to content

[Bug]: NEXTAUTH_URL is overridden #1345

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

Closed
2 tasks
phbernard opened this issue May 6, 2022 · 2 comments · Fixed by #1360
Closed
2 tasks

[Bug]: NEXTAUTH_URL is overridden #1345

phbernard opened this issue May 6, 2022 · 2 comments · Fixed by #1360
Assignees
Labels
type: bug code to address defects in shipped code

Comments

@phbernard
Copy link

phbernard commented May 6, 2022

Summary

Because the plugin supports NextAuth.js, it sets NEXTAUTH_URL automatically at deploy.

However, it does so every time, even when NEXTAUTH_URL is already explicitly initialized as a regular environment variable.

This behavior is misleading. Someone who sets NEXTAUTH_URL and doesn't know about NextAuth.js support has no reason to think NEXTAUTH_URL will be changed. It also blocks people who need to set NEXTAUTH_URL to a particular value (more about this below).

Suggested change:

  • When about to set NEXTAUTH_URL, do nothing when it is already defined.
  • Log this particular behavior so people who know about NextAuth.js support are not surprised.

As an aside, why would you want to explicitly set NEXTAUTH_URL? For example in case of multi-domains support. This can be achieved with multiple domains and a middleware. You can find an advanced example of this in the Vercel Platform Starter Kit. A classic setting would be for the app to serve both example.com (+ www.example.com) and app.example.com. As the subdomain suggests, NEXTAUTH_URL will be set to https://app.example.com. Currently, the plugin just doesn't allow it.

Steps to reproduce

I don't think this issue needs any guidance in this respect. The behavior is straightforward and fits in 5 lines of code.

A link to a reproduction repository

No response

Plugin version

@netlify/[email protected] from Netlify app

More information about your build

  • I am building using the CLI
  • I am building using file-based configuration (netlify.toml)

What OS are you using?

No response

Your netlify.toml file

`netlify.toml`
# Paste content of your `netlify.toml` file here

Your public/_redirects file

`_redirects`
# Paste content of your `_redirects` file here

Your next.config.js file

`next.config.js`
# Paste content of your `next.config.js` file here. Check there is no private info in there.

Builds logs (or link to your logs)

Build logs
# Paste logs here

Function logs

Function logs
# Paste logs here

.next JSON files

generated .next JSON files
# Paste file contents here. Please check there isn't any private info in them
# You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.
@phbernard phbernard added the type: bug code to address defects in shipped code label May 6, 2022
@ericapisani ericapisani self-assigned this May 13, 2022
@kodiakhq kodiakhq bot closed this as completed in #1360 May 25, 2022
@ericapisani
Copy link

@phbernard Thanks so much for reporting this and for the explanation of the use case for explicitly setting the environment variable.

I just merged a PR which should fix this, but if for some reason there's still issues around this functionality feel free to reach out.

@aleehedl
Copy link

@ericapisani I was wondering if .env files could be taken into account for this as well? I was still experiencing this bug until I found out from the pull request comments that next.config.js was the right place for setting the user-defined NEXTAUTH_URL. In my case, I write the values to .env file dynamically in the Netlify build step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants