# NextAuth redirects to wrong URL

**URL:** <https://answers.netlify.com/t/nextauth-redirects-to-wrong-url/76938>\
**Category:** Support\
**Tags:** redirects, nextjs\
**Created:** [October 7, 2022, 12:19am UTC](https://answers.netlify.com/t/nextauth-redirects-to-wrong-url/76938 "2022-10-07T00:19:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![baltasaurusrex](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/baltasaurusrex/32/41902_2.png) [@baltasaurusrex](https://answers.netlify.com/u/baltasaurusrex)\
**Post date:** [October 7, 2022, 12:19am UTC](https://answers.netlify.com/t/nextauth-redirects-to-wrong-url/76938/1 "2022-10-07T00:19:30Z")

</div>

My netlify site name is wordnerdbeta.netlify.app.

But I have a paid domain which goes by the name thewordnerd.xyz, which is what I’ve placed in my .env file’s NEXTAUTH\_URL variable, as well as the authorized redirect URI in my OAuth provider’s (Google) settings.

I don’t have any build problems, it builds fine, I just keep being redirected to this URI  
 ![Screen Shot 2022-10-07 at 8.16.48 AM](https://global.discourse-cdn.com/netlify/original/3X/1/7/17b55a6c4e685ea7ef90b4c3da71ccdd2a8e7098.png)

Instead of this URI: [https://thewordnerd.xyz/](https://thewordnerd.xyz/)

And the error I keep getting is:

# This site can’t be reached

Check if there is a typo in 633f6af1afc86e353f49db97–wordnerdbeta.netlify.app.

DNS\_PROBE\_FINISHED\_NXDOMAIN

Any help would be appreciated. Thanks.

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [October 9, 2022, 12:20pm UTC](https://answers.netlify.com/t/nextauth-redirects-to-wrong-url/76938/2 "2022-10-09T12:20:39Z")

</div>

This one looks related:

> [@URI callback redirects to deploy build and not domain site](https://answers.netlify.com/t/76469/):
>
> I’m working with next-auth to have users use Google SSO to sign into my app. I’ve done this before on Netlify but something is off about the build. My site is at: [https://cds-social.netlify.app](https://cds-social.netlify.app/) and the repo is [https://github.com/ryanjames1729/cds-social](https://github.com/ryanjames1729/cds-social). According to the docs, the callback url for Google SSO should be \*/api/auth/callback/google, where \* is your domain. But, when my app tries to authorize a user, Netlify is redirecting the callback to –/api/auth/callback/google rather than /api/…

There’s no solution yet as we’re still waiting for them to follow-up and were not able to reproduce the issue. In your case, I can see that happen however, I’m never asked to log into my Google Account, so it seems something else is off.

In your case, I can see that you’re hardcoding the wrong values:

 ![image](https://global.discourse-cdn.com/netlify/original/3X/1/e/1eca38125b9c2083ae8cf47503c7c68e5dda871e.png)

Your form is pointing to that URL, thus the problem.

---

<div class="post-metadata">

**Author:** ![p3t3r67x0](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/p3t3r67x0/32/41962_2.png) [@p3t3r67x0](https://answers.netlify.com/u/p3t3r67x0)\
**Post date:** [October 9, 2022, 12:28pm UTC](https://answers.netlify.com/t/nextauth-redirects-to-wrong-url/76938/3 "2022-10-09T12:28:09Z")

</div>

> [@baltasaurusrex](#):
>
> Check if there is a typo in 633f6af1afc86e353f49db97–wordnerdbeta.netlify.app.

seems to be a typo on copy and paste, check dashes. may I’m wrong?

---

<div class="post-metadata">

**Author:** ![rjames](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/rjames/32/23695_2.png) [@rjames](https://answers.netlify.com/u/rjames)\
**Post date:** [October 9, 2022, 12:41pm UTC](https://answers.netlify.com/t/nextauth-redirects-to-wrong-url/76938/4 "2022-10-09T12:41:51Z")

</div>

Yeah I’m having that same issue. I’ve built with next-auth in the Spring of this year without this issue. When I deploy locally or not on Netlify I don’t get the redirect errors. I really want this to work because on Netlify though and not turn to another tool to deploy.

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [October 9, 2022, 12:43pm UTC](https://answers.netlify.com/t/nextauth-redirects-to-wrong-url/76938/5 "2022-10-09T12:43:43Z")

</div>

As we’re discussing in your other thread @rjames, I haven’t been able to reproduce the error in your case yet. Let’s keep your discussion going on in your thread.

---

<div class="post-metadata">

**Author:** ![baltasaurusrex](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/baltasaurusrex/32/41902_2.png) [@baltasaurusrex](https://answers.netlify.com/u/baltasaurusrex)\
**Post date:** [October 10, 2022, 11:51am UTC](https://answers.netlify.com/t/nextauth-redirects-to-wrong-url/76938/6 "2022-10-10T11:51:39Z")

</div>

Nothing is hardcoded on my end, this is all next-auth’s territory. My code just looks like this:

 ![Screen Shot 2022-10-10 at 7.50.57 PM](https://global.discourse-cdn.com/netlify/original/3X/c/1/c15303afb2f7c710c93804e7bb157acfb1929a3a.png)

Once you click Sign in with Google, idk how to change what gets rendered there.

---

<div class="post-metadata">

**Author:** ![baltasaurusrex](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/baltasaurusrex/32/41902_2.png) [@baltasaurusrex](https://answers.netlify.com/u/baltasaurusrex)\
**Post date:** [October 10, 2022, 12:09pm UTC](https://answers.netlify.com/t/nextauth-redirects-to-wrong-url/76938/7 "2022-10-10T12:09:19Z")

</div>

Got it to work by setting the environment variables on Netlify itself.

 ![Screen Shot 2022-10-10 at 8.05.36 PM](https://global.discourse-cdn.com/netlify/original/3X/2/5/2596c4b8ede144ee6a0d5be146914765dae9fbf0.png)

The “hardcoded” value is now showing the correct URL. This is the solution, but I’d also like to know _why_ this is the solution, to understand how to avoid this problem moving forward. Why, when I already set the .env variable in my local code, was it changed to something else when I published it to Netlify?

---

<div class="post-metadata">

**Author:** ![kylesloper](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/kylesloper/32/18398_2.png) [@kylesloper](https://answers.netlify.com/u/kylesloper)\
**Post date:** [October 10, 2022, 12:39pm UTC](https://answers.netlify.com/t/nextauth-redirects-to-wrong-url/76938/8 "2022-10-10T12:39:48Z")

</div>

Thanks for sharing this @baltasaurusrex. People like you make the Netlify Community great :netliheart:
