# Next.js login fails with custom domain in hosts file, but not localhost

**URL:** <https://community.auth0.com/t/next-js-login-fails-with-custom-domain-in-hosts-file-but-not-localhost/151027>\
**Category:** Get Help\
**Tags:** reports, support-center\
**Created:** [November 5, 2024, 11:42pm UTC](https://community.auth0.com/t/next-js-login-fails-with-custom-domain-in-hosts-file-but-not-localhost/151027 "2024-11-05T23:42:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![milotis](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/milotis/32/33224_2.png) [@milotis](https://community.auth0.com/u/milotis)\
**Post date:** [November 5, 2024, 11:42pm UTC](https://community.auth0.com/t/next-js-login-fails-with-custom-domain-in-hosts-file-but-not-localhost/151027/1 "2024-11-05T23:42:55Z")

</div>

Summary

Auth0 Login works with the app from the Auth0 Next.js QuickStart when using localhost, but attempting to use a custom domain by configuring the hosts file does not.

Environment

- Node Version Manager 0.39.7
- Node v18.19.0
- “@auth0/nextjs-auth0”: “^3.5.0”

How to recreate the issue

- Install Windows Subsystem for Linux Ubuntu-24.04
- Install nginx on WSL
- Follow the Auth0 quick start with Next.js to create a new app on Windows Subsystem for Linux
- Test login and logout functionality when the app is configured to use localhost (works)
- Configure nginx as reverse proxy to point to next.js app and restart nginx
- Think of a custom domain name, e.g. [dev.company.com](http://dev.company.com)
- Update the hosts file on windows with a custom domain to point to the IP of Windows Subystem for Linux
- Reconfigure the app to use a custom domain
- Relaunch the app and attempt to test the login functionality - this might require clearing the browser history/cache. The user will get redirected to the login page, but the login process fails on the callback url with an http status code 302.

[Auth0 Next.js SDK Quickstarts: Login](https://auth0.com/docs/quickstart/webapp/nextjs/01-login)

The only error that happens is before the login process even happens

Error: Route “/api/auth/[auth0]” used `params.auth0`. `params` should be awaited before using its properties. Learn more: [Dynamic APIs are Asynchronous | Next.js](https://nextjs.org/docs/messages/sync-dynamic-apis)

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 6, 2024, 12:37am UTC](https://community.auth0.com/t/next-js-login-fails-with-custom-domain-in-hosts-file-but-not-localhost/151027/3 "2024-11-06T00:37:23Z")

</div>

Hi @milotis,

Thanks for reaching out to the Auth0 Community!

> [@milotis](#):
>
> Relaunch the app and attempt to test the login functionality - this might require clearing the browser history/cache. The user will get redirected to the login page, but the login process fails on the callback url with an http status code 302.

Could you check your [Auth0 Logs](https://manage.auth0.com/#/logs) to determine the behavior you are experiencing? Then, please share your findings with me here.

Secondly, if the login flow fails on the callback URL, there might be issues around the URL itself. Is this callback URL the same one you used during your localhost login attempts?

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![milotis](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/milotis/32/33224_2.png) [@milotis](https://community.auth0.com/u/milotis)\
**Post date:** [November 6, 2024, 5:52pm UTC](https://community.auth0.com/t/next-js-login-fails-with-custom-domain-in-hosts-file-but-not-localhost/151027/4 "2024-11-06T17:52:02Z")

</div>

The logs show two entries ‘Success Login’ and and ‘Success Exchange of Authorization Code’ and I should have also stated the browser lands on an NGinx 502 Bad Gateway on the callback.

The callback URL uses the domain and not localhost.

```auto
https://dev.company.net/api/auth/callback?code=CODE&state=STATE

```

 ![image](https://global.discourse-cdn.com/auth0/original/3X/9/0/9094a76a3fe70b8e059f086e34bff45cf858abfc.png)  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/d/2/d2491b0b15fae56c28948b64758e9449aa46b57b.png)  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/f/4/f489546685dacd6516aff99e767e539dbd578e6f.png)

---

<div class="post-metadata">

**Author:** ![milotis](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/milotis/32/33224_2.png) [@milotis](https://community.auth0.com/u/milotis)\
**Post date:** [November 7, 2024, 8:09pm UTC](https://community.auth0.com/t/next-js-login-fails-with-custom-domain-in-hosts-file-but-not-localhost/151027/5 "2024-11-07T20:09:17Z")

</div>

I tried creating a new project with Next.js 14.2.17 just in case it was because of the recent breaking changes, but still get the same error.

Ok, I didn’t believe it was nginx, but seems to be this error. Found some nginx settings online to configure buffer sizes, etc. Gotta find one that doesn’t throw errors I think.

upstream sent too big header while reading response header from upstream

No combination of increasing the header size has worked; so I just deleted everything in the user’s app\_metadata and was able to login. So, some secret combo of settings will get stuff working again.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 8, 2024, 8:41pm UTC](https://community.auth0.com/t/next-js-login-fails-with-custom-domain-in-hosts-file-but-not-localhost/151027/6 "2024-11-08T20:41:44Z")

</div>

Hi @milotis,

Thanks for the update.

If you are experiencing a 502 error, that is indicating a server error.

I have just checked your tenant settings and found that you do not currently have a custom domain configured.

Please check out the following documentation:

- [Configure Custom Domains with Auth0-Managed Certificates](https://auth0.com/docs/customize/custom-domains/auth0-managed-certificates)
- [Configure Features to Use Custom Domains](https://auth0.com/docs/customize/custom-domains/configure-features-to-use-custom-domains)

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![milotis](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/milotis/32/33224_2.png) [@milotis](https://community.auth0.com/u/milotis)\
**Post date:** [November 15, 2024, 7:48pm UTC](https://community.auth0.com/t/next-js-login-fails-with-custom-domain-in-hosts-file-but-not-localhost/151027/7 "2024-11-15T19:48:26Z")

</div>

Thank you for checking, but I have verified the issue is I did not properly configure nginx to handle the large header size resulting from the user’s app\_metadata.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 18, 2024, 6:53pm UTC](https://community.auth0.com/t/next-js-login-fails-with-custom-domain-in-hosts-file-but-not-localhost/151027/8 "2024-11-18T18:53:11Z")

</div>

Hi @milotis,

Thanks for sharing your solution. I’m glad it’s working now.

Let us know if you have any more questions.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 2, 2024, 6:53pm UTC](https://community.auth0.com/t/next-js-login-fails-with-custom-domain-in-hosts-file-but-not-localhost/151027/9 "2024-12-02T18:53:16Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
