Session is undefined after successful credentials login - No session cookie #12859
Unanswered
abgonzalez93
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey everyone 👋 I'm using NextAuth.js with CredentialsProvider and trying to mock a login flow using
/login/[token]
. The login endpoint (/api/login
) returns the correct user and calls signIn() server-side. The login works, but the session is always undefined.✅ What works
/api/login
200
OKauthjs.callback-url
andauthjs.csrf-token
❌ What's broken
auth()
(server) anduseSession()
(client) returnnull
authjs.session-token
is not being set🧪 Console logs
🧩 Code summary
💡 Context
I initially tried calling signIn() inside a Server Action, but got this error:
❌ Cookies can only be modified in a Server Action or Route Handler
So I moved the logic to a route handler (
/api/login
). It works, but no session cookie is set — and session remains null.❓ Questions
authjs.session-token
not being set?signIn()
from a route handler?Thanks in advance for any help 🙏
Beta Was this translation helpful? Give feedback.
All reactions