Weird next-auth behaviour
I have a weird issue happening lately with next-auth.
Whenever I call
signIn('provider')
, I get redirected to /api/auth/signin
, and if on that page I click on whichever provider, I get redirected again to this same page. No errors are logged, even with debug: true
set in nextAuth itself. On localhost, everything runs fine, even with a ngrok setup on top of it. I've already stripped away all of my custom configurations of next-auth, double checked my .env
variables which seem to be in line with my production server (that is running fine). And the problem can't lie in the provider itself, as it's happening with every single provider, + email login (which doesn't trigger any of the next-auth stuff, and just redirects me back to /api/auth/signin
.
Would anybody know where I can continue to debug this?
My environment runs on:
- VPS setup with NGINX
- A subdomain (staging.domain.com)
- Cloudflare18 Replies
Could cloudflare proxy be affecting it?
Yeah I thought about that as well, and turned the proxy off, but didn't seem to change the behaviour at all
Do you get the response code 302 too (instead of 200)? I'm experiencing similar redirect to
/api/auth/signin
but for me it's also in the happening in the localhostThe only thing slightly related was this issue, but the fix they suggested there is outdated: https://github.com/t3-oss/create-t3-app/issues/952
GitHub
bug: Discord login not working · Issue #952 · t3-oss/create-t3-app
Provide environment information The Discord login don't work on second try. Describe the bug You can login with discord on your first try, it works. But when you logout and login again it don&#...
Yeah I indeed get a 302 from the api call
I have decided to change the way I'm apporaching this now, I now log in via the production (non subdomain) website, and share the cookies to my subdomain as well and use that to log in.
So now I don't log in via the subdomain anymore, since I couldn't find out why this was happening
Just to follow up - I updated my system and the behaviour disappeared. As I updated many things, I'm not sure what affected it but most likely it was my Node version
This is a nightmare, the redirect behaviour is back, out of nowhere 🤦
Yepp. Are you on a sub domain as well?
I suspect the issue to be something revolving around the cookies on the sub domain, but no matter how much I messed with the cookie settings nothing seemed to work.
For me it seems the callbacks are not even fired properly, I get no cookies
No, I meant, the cookies before the session cookie is made. The csrf and the other one
Set up a question on StackOverflow today, too
Stack Overflow
next-auth signin redirects back to /api/auth/signin before the call...
I'm trying to build a simple Next.js app with next-auth. It seems I keep getting redirected from api/auth/signin back to the same api/auth/signin whenever I try to run any authentication methods. The
My callback isn't being hit either, it seems to just skip over it and redirect the page back to /signin. But I noticed on my subdomain those two cookies missing
you mean these?
![No description](https://cdn.answeroverflow.com/1141686444184850464/image.png)
I get none of them
The POST request payload includes the
csrfToken
thoYeha I don't have the csrf nor the callback URL set whenever I do the api call to the signin. The post req also does not return me any "Set-Cookie" header, while it's supposed to.