nextAuth working only locally (not on vercel deployment)
I've been trying for a day now. I don't know the issue. I can't even get an error. When the nextAuth singIn() method runs, I just get the /api/auth/error page.
100 Replies
I'll have to add to this: sometimes it works miraculously, without anyone changing anything, seemingly random.
I can also observe the /api/auth/singin page displaying no providers (which might be the source of the error)
I got google and discord providers
Didn't have this happen to me at all, so I can't say what's causing it, have the repo publicly available for possible replication?
No clue without code
I just found out that I can run a working commit on vercel, but as soon as I promote that same vercel deployment to production, it breaks
It's a private repo🙃 , I can share code tho (I just don't know what to share)
You’re missing NEXTAUTH_SECRET as environment variable
It’s required in prod
Optional elsewise
nop
I can try changing it
So what are the logs saying
which ones
I can't seem to get any errors
The ones that fail lol
well the terminal says nothing
the chrome console says nothing
vercel functions just show the get request for /api/auth/error
What if you build it and run it locally
I can try again, but pretty sure that yields nothing
ye, it works locally
so no errors
also if you set env to production
wut where
in env variables?
am I supposed to have an env variable that says wether or not I am in prod ?
You don’t need it no
I only have a database env for dev and prod that I switch around
so how do I change this ?
just set NODE_ENV
to production
build and run
NODE_ENV=production
?yes
I did npm run build and npm start and it still works
idk wtf you done then lol
does the build fail
what part fails
like, npm run build?
vercel build
uhh no I don' think so
I can post some warnings
so it shows a ready state etc
like that
ye ofc
^^
but the screen is white?
blank
what do you mean?
the page*
uhh
no why would it be white
is it blank
no
so the page works
yes
what part doesnt work
oauth?
everything works (I think, most is behind the auth wall)
its just that when I go to signIn() or manually go to /api/auth/signin
you doing oauth?
signIn() gives the api/auth/error page
or password stuff
oauth
only that
nothing more
and you added
https://vercel.deployment.example.com/api/auth/callback/discord
https://vercel.deployment.example.com/api/auth/callback/google
as a callback on google and discordand /api/auth/signin is just empty
and its not localhost
yes yes ofc, it works locally and I am not getting an invalid callback uri error
you doing
signIn()
or signIn("google") / signIn("discord")
actually, the vercel build in preview gives me the invalid callback uri error
tried both, no difference
for example your discord oauth
how is the settings on developer portal setup
the callback uri?
sure
http://localhost:3000/api/auth/callback/discord and the same for our websites
ill send you an example
its not a callback uri error
thats really not it
yeah thats obv not going to work on vercel??
vercelurl.com/api/auth/callback/discord
you cant do localhost
and expect it to work when deployed on vercel
we are talking past each other I think
I am saying
1. there are more
2. even if it was blank it would not make a difference
because I would an invalid callback uri error then
but that is not the error I am getting
I am getting nothing except a redirect to /api/auth/error
so going to api/auth/signin goes to that
no
calling the signIn() function, through a button, goes to that
I can manually go to /api/auth/signin and see this
>no providers
show the button
and the onclick
this is part of a sidebar
what if you do signIn("discord")
we also tried signIn("discord") and signIn("discord", {})
I'll try again, sure
I think its not the button, the button is redirecting to ap/auth/error because there are no providers registered most likely
as I said, I can observe there being no providers on /api/auth/signin
that is sort, the first issue
show your next auth config then
its
api/auth/[...nextauth].ts
right exactly same as me and works
I think running a working commit on vercel and it breaking as soon as its promoted to production is the closest I got to the problem
you set env variables with the right names on vercel?
all set without ""
promoted to development or production
this works
yh
when I click, promote to production, it breaks
and if you go to functions and look for errors
what then
on the working one or on production
prod is my guess
prod yh
also promoting to production gives your site a new url
make sure that url is added as callback uri
again, if it isn't I will just get this error
but then I know that the issue is basically fixed
the prod url is different from preview guess thats whats breaking it though
well I have it running on 2 extra non-vercel domains
it doesn't make a difference if the callback uri is set
weird
also
It works currently, but It will break soon
it randomly switches between working and not working sometimes
but the majority is non-working
send url?
pm
Fixed or?
No🙃
Can you make a reproduction using the base CT3A and make it public?
I will do tomorrow, I am considering redoing the entire app at this point
Don't have to re-do it. Just re-produce the issue.
Sounds like a DB integration Issue honestly.
I'm just not sure exactly how to help you out with nothing to go on.
Yeah the "there is no error thing" is the biggest problem
Can you provide a screenshot of your Vercel logs?
Even if there's an error, unless it's really obvious, there's likely little we can do.
It's like saying "Help me, I have an issue" whilst the issue could literally be under a rock in the sea xD
Kinda hard with development to pin-point.
@Johnson I am aware that this sounds stupid, but test npx prisma db push/sync, and test nextauthurl to be vercel's, see if that shows any errors locally when you're in dev. environment.
Yeah true