Session cookie not being created
As title states, I can login using the api fine. The sessions are created in the database. However, no cookies are being made and thus the sessions always result in null.
I tried experimenting with subdomain cookies where the behaviour first started, but now I can't get the cookies to create at all anymore in any browser.
I don't have anything special in the auth object:
And I'm quite stumped. It worked for a second, I don't think I change anything and now it refuses to do anything cookie related.
EDIT: forgot to mention this is in development on localhost
26 Replies
I also have the same problem, it only sets a session using client side "signIn" function
Any chance it is intended considering the cookie is client side? Seems pretty unintuitive to me not gonna lie. But I'm not a very proficient programmer
someone replied to the post that i made
okay i found the solution you just need to follow this
https://www.better-auth.com/docs/concepts/api
API | Better Auth
Better Auth API.
for returning the session and getting the session
for example
const {headers} = await auth.api.signInEmail({
returnHeaders: true,
body: {
email,
password,
},
asResponse: true,
})
return {
status: "success",
Response: redirect("/dashboard", {
headers,
}),
}
you're a life safer! thank you so much!
Was your issue after logging in the cookie isn't being sent to the browser? I'm having that issue right now. It was working but it stopped issuing out the cookie after signing in with email & password
yes, only using the server side api though. did you change crossSubDomain?
i redacted some information but here's my setup

should i remove the crossSubDomain?
Yeah, my server is independant. I have a frontend and mobile that communicates to it.
so from what I've gathered in my own setup the crossSubDomain instantly causes the cookie to fail to be set. Really unsure why, whether it's a bug or whether I'm misunderstanding how crossSubDomain cookies work
I've literally tried everything haha it's driving me mad. So your setup is fixed?
without cross sub domain hahaha, currently I have two allowed origins and base url is set to be my app domain.
but it causes two different sessions to be possible
what i haven't tried yet is crossSubDomain set to false and passing
domain: '.example.com'
I just fixed it!
hahaha
including the crossSubDomain
Not sure what you're using as a server but im using hono so i needed to amount then in the better auth config, i had to add basePath so '/api/v1/auth'
and it worked


Glad! I'm using RRv7/Remix fullstack. My cross sub domain cookies dont work period so it's most likely user error haha
ahhh got it!
lol i spent too long on this
This is my setup in case anyone smarter can figure it out. tried everything basically

tbf maybe it just doesn't work on localhost
What does your sign in code look like?
Also have you tried to do the bare minimum config to see if it works?
Both of these actions work fine when crossSubDomain is disabled, and instantly fail to set the cookie when it is enabled.
Eve with minimum config.

you don't need to use the authClient signIn email because you are already using the server side authentication
the clientAction whole purpose now is the error handling using client components (e.g toasts)
on the client side you should use the serverAction() from remix/rr7 that will execute/ping the server-side action function
I know! I tried out authClient to see if that would fix the issue with crossSubDomain cookies not working. Both work fine in their own way, but I read in #general that the authClient can do rate limiting on its own while with the api you need to do it manually? Regardless both work fine I just sent both of them here to show that for both the crossSubDomain cookies aren't working
oh okay, mb I can't read lol. does it really do rate limiting? when using authClient? can you forward here so that i can take a look also. 🙂
This is the message I saw yday, not sure if it's applicable to rrv7 but I'd assume so
but error handling in client side imo is not as great, though that's most likely just a skill issue on my part
It's not just you; if you're used to server-side error handling, you'll hate error handling on the client side.