Skip to content

[Bug]: NEXTAUTH_URL is set as prod URL on deploy preview #1611

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
1 of 2 tasks
colbyfayock opened this issue Sep 9, 2022 · 3 comments · Fixed by #1613
Closed
1 of 2 tasks

[Bug]: NEXTAUTH_URL is set as prod URL on deploy preview #1611

colbyfayock opened this issue Sep 9, 2022 · 3 comments · Fixed by #1613
Assignees
Labels
type: bug code to address defects in shipped code

Comments

@colbyfayock
Copy link

Summary

While trying to create a PR with Deploy Preview that includes Next.js, I noticed the NEXTAUTH_URL value was being overridden.

https://app.netlify.com/sites/50reactprojects/deploys/631aa4b96d37524db46b4ee1

10:28:50 PM: NextAuth package detected, setting NEXTAUTH_URL environment variable to https://50reactprojects.com/

I think I see 2 problems here:

Steps to reproduce

  1. Create a deploy preview where the production site does not have NextAuth.js installed, but the preview does
  2. When the build/deploy runs, it sets NEXTAUTH_URL as the production site

A link to a reproduction repository

colbyfayock/50reactprojects.com#22

Next Runtime version

4.21.3

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`
[build]
  publish = ".next"
  command = "yarn build"

Your public/_redirects file

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

Your next.config.js file

`next.config.js`
/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: false, // to prevent double entries
};

module.exports = nextConfig;

Builds logs (or link to your logs)

Build logs
https://app.netlify.com/sites/50reactprojects/deploys/631aa4b96d37524db46b4ee1

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.
@colbyfayock colbyfayock added the type: bug code to address defects in shipped code label Sep 9, 2022
@ericapisani ericapisani self-assigned this Sep 9, 2022
@kodiakhq kodiakhq bot closed this as completed in #1613 Sep 9, 2022
@nickytonline
Copy link

Thanks for reporting this @colbyfayock! It should be all sorted now.

@colbyfayock
Copy link
Author

awesome thank you all!

@kachar
Copy link

kachar commented Sep 28, 2022

@nickytonline @colbyfayock

Since the #1613 PR got merged we've got a regression on our Netlify account regarding NextAuth deployments.
(Version 4.23.1 (2022-09-09))

We didn't set the environment var NEXTAUTH_URL manually (as the docs advise), so we ended up having the build redirecting users after login to https://develop--project-xxx-staging.netlify.app/login instead of our main custom domain URL (ex. https://app.project-xxx.com/login.

The custom domain is linked to our develop branch for automated deployments.

We've resolved the situation by manually setting the env var to our custom domain, however, we lose the ability to see and login to the preview builds if we want to use custom domains.

I guess we can enhance the functionality even further to use custom domains when they are set and if not to fall back to the deploy preview URLs.

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.

4 participants