Cookies not working localhost when API already in aws lambda (hono)
I'm trying to work with front-end in localhost but using the api in aws lamba. The cookies not working. When sign-in, the request returns 200 but getCookies return null and not redirecting to dashboard. Anyone already had this issue?!
16 Replies
Hi Guilherme, could you show your better-auth config?

This a betterAuth config on my hono
at the beginning I also had problems with the sessions, in my better-auth config after configuring these properties I had no more problems:
storeSessionInDatabase: true,
preserveSessionInDatabase: true
But i think, the problem is that my client not "see" cookies because is from my api domain (and my client is in localhost)
mmm okey I understand, it could be problems with the trustedOrigins property?
i set both, but when sign-in the cookies not appears on devtools
if you are in dev mode you should not have cross domain cookies enabled as localhost is the same domain
you can use node_env variable to check if app is in prod and then set the boolean
my client is localhost, but my server is in aws lambda (not localhost)
Then you should probably configure
defaultCookieAttributes
and trustedOrigins
in your auth config. you can find everything in their docsI tried to configured many thinks in both, but with no success, that's why i open this question
Hmm. I've had a lot of problem with cookies honestly, but most of them were fixed by going into incognito. (Some thing were cached that werent supposed to) Which made debugging very hard. Maybe this would be your solution.
guilherme, I share with you my better-auth configuration in the server:
is a little long the configuration but maybe it will help you, as sebastian said and I told you before it must be a problem of the trustedOrigins or defaultCookieAttributes property.
Thanks! I'll take a look on this file!!
If youre still trying for a solution, this is the only thing you need to do:
We have a staging setup but for our actual prod setup I would obviously restrict it to lax
even with lax in development mode it should work the same, but just in case try with none