I deployed a nextjs site, and specified the next-auth URL in the UI environment variable, however inspecting the functions I noticed this
https://drive.google.com/file/d/1gFtrX65mSuO3JjsKNkBK8uJyHFIzb-D7/view?usp=drivesdk
I’ve tried to redeploy several times changing the URL in the UI. Unfortunately I couldn’t figure it out.
I deployed directly from a Linked GitHub repo which has a .env.example file, where I set next-auth URL to localhost, I doubt netlify would use that.
I’ve made a previous deployment from the CLI, (manual deploy) It didn’t give me any issue. But I don’t want to manually deploy this because of CI.
Any solution for this?
Chances are that file is overriding the ones in the UI? Though, if you could share the site name or deploy ID, we could investigate further.
I also tried redeploying (with clear cache) after deleting the .env.example from the repo it still sets next-auth URL to localhost:3000
Site name: thirdbook
It’s happening because of:
Because of this:
opened 10:39AM - 06 May 22 UTC
closed 06:59PM - 25 May 22 UTC
type: bug
### Summary
Because the plugin [supports NextAuth.js](https://github.com/netl… ify/netlify-plugin-nextjs/pull/1309), it [sets `NEXTAUTH_URL` automatically](https://github.com/netlify/netlify-plugin-nextjs/blob/346aad1a46e0e774b68d0436a193909689a6eb49/plugin/src/index.ts#L78) 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`](https://github.com/netlify/netlify-plugin-nextjs/blob/346aad1a46e0e774b68d0436a193909689a6eb49/plugin/src/index.ts#L78), 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](https://github.com/vercel/platforms/blob/main/pages/_middleware.ts). 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.](https://github.com/netlify/netlify-plugin-nextjs/blob/346aad1a46e0e774b68d0436a193909689a6eb49/plugin/src/index.ts#L78)
### A link to a reproduction repository
_No response_
### Plugin version
@netlify/plugin-nextjs@4.7.0 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
<details>
<summary>`netlify.toml`</summary>
```toml
# Paste content of your `netlify.toml` file here
```
</details>
### Your public/_redirects file
<details>
<summary>`_redirects`</summary>
```toml
# Paste content of your `_redirects` file here
```
</details>
### Your `next.config.js` file
<details>
<summary>`next.config.js`</summary>
```toml
# Paste content of your `next.config.js` file here. Check there is no private info in there.
```
</details>
### Builds logs (or link to your logs)
<details>
<summary>Build logs</summary>
```
# Paste logs here
```
</details>
### Function logs
<details>
<summary>Function logs</summary>
```
# Paste logs here
```
</details>
### .next JSON files
<details>
<summary>generated .next JSON files</summary>
```
# 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.
```
</details>
the URL in your config is given preference.
2 Likes
Thanks a bunch. The issue is resolved.
1 Like