Next.js Discord

Discord Forum

Live site taking to localhost in Next Auth

Answered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
Hi, im using next auth, in prod when im clicking on sign in with google im getting redirected to localhost, any idea what could be the cause of this?
Answered by averydelusionalperson
Do you have NEXTAUTH_URL in environment variables?
View full answer

29 Replies

Spectacled bearOP
anyone?
Do you have NEXTAUTH_URL in environment variables?
Answer
American Crow
Forgot to set an env var on Vercel or reading headers wrong
^ check this
and don't forget to add your domain in authorized redirect urls in google dashboard
Nice Name BTW
@averydelusionalperson Do you have `NEXTAUTH_URL` in environment variables?
Spectacled bearOP
It is not there, but it was working before
yes, it'll work in local
but to make it work in prod
you need to add that env variable
or else it will redirect to localhost
@averydelusionalperson Nice Name BTW
Spectacled bearOP
it was working in prod too
and one thing we have a staging environment, it is working fine even now without this variable
hmm, okay then, what's the issue?
Spectacled bearOP
in prod it is taking to localhost
yeah IK that
what do you think is causing it?
Spectacled bearOP
that is what im asking.
the app was working in prod without this env
I shared what I think is causing it, you're rejecting that idea. So I'm asking you what else do you think is causing it?
Spectacled bearOP
Yeah it fixed the issue, but still im curious we were not using this env var before and it was working fine.
idk what black magic you did before lol, but it nextauth_url is necesarry AFAIK
if your problem is solved, consider marking answer as solution
🫡
Morelet’s Crocodile
@averydelusionalperson Hey, i am facing same issue. I do have NEXTAUTH_URL in env variables
@Morelet’s Crocodile <@1011594178934878248> Hey, i am facing same issue. I do have NEXTAUTH_URL in env variables
hello momo, if you are having any issues, please create another thread with your issue details