Session-token cookie not set #4089
Replies: 6 comments 14 replies
-
Hey @Mikhail1Demianenko I am facing the same issue, as soon as I add this object
Session cookie won't get generated and thus result in an unauthenticated session. |
Beta Was this translation helpful? Give feedback.
-
mine works like this
|
Beta Was this translation helpful? Give feedback.
-
I'd just like to add that it took me ages to figure this out - but it's mentioned in the first line of the original question. The NextAuth sessionCookie needs to be created on the apex domain, in order to be accessible across subdomains. When I originally configured my Next.js project, I took sensible defaults which involved them creating a 308 Redirect from mydomain.dev -> www.mydomain.dev, which meant that I was effectively authing on a subdomain. I had to remove this redirect (I wasn't using it anyway) and it worked. |
Beta Was this translation helpful? Give feedback.
-
Next-Auth Session-token issues have been hindering me for half month. |
Beta Was this translation helpful? Give feedback.
-
For people arriving here when googling for Check that all your I had following in my codebase, and the second line caused session-token to be overridden to empty string, thus causing log out
|
Beta Was this translation helpful? Give feedback.
-
anyone have success getting the session token cookie in subdomains when using |
Beta Was this translation helpful? Give feedback.
-
Question 💬
Hello community.
Thank you for an amazing library!
I am trying to create a nextjs app with many subdomains, such that the user can authenticate using the apex domain (no subdomain) and share the auth state across the rest subdomains.
This issue has been discussed here, here and documented here.
Basically, what is suggested is to add the following object into the object we pass to the
NextAuth
function in[...nextauth].js
:(In the object I hardcoded the values for local dev env, so it is easier to read)
With the key thing in the object being the dot before the domain.
Without this object, the cookie after login is set correctly:
And the cookies set in the browser are just 5 in total
However, with that object I have the following picture:
The session-token cookie has disappeared. And, of course, authentication status results in
unauthenticated
, even though a session gets created.Moreover, browser now has 25 cookies set:
Having gone through all the above posts it seems to have worked for others, but sadly not for me
Does anyone have any idea what I am doing wrong?
Thank you!
How to reproduce ☕️
[...nextauth].js
file withnext-auth v.4.2.1
:Contributing 🙌🏽
Yes, I am willing to help answer this question in a PR
Beta Was this translation helpful? Give feedback.
All reactions