NextAuth redirects to wrong URL

My netlify site name is

But I have a paid domain which goes by the name, 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

Instead of this URI:

And the error I keep getting is:

This site can’t be reached

Check if there is a typo in 633f6af1afc86e353f49db97–


Any help would be appreciated. Thanks.

This one looks related:

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:

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

1 Like

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

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.

1 Like

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.

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

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

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

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?


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