Cookie “__Secure-session_token” has been rejected for invalid prefix.
i really dont know why, but i can't set cookie for client and cant login in my app
26 Replies
are you trying to set secure cookies on localhost?
yes
but on local host working without __Secure prefix
secure cookies works on https only
yea i know
on prod with __Secure prefix cookie can't setted
show your auth config
with error on console "Cookie “__Secure-session_token” has been rejected for invalid prefix."
oh god
i can set true on local for all options and i can set cookie becouse without __Secure prefix
most things have sensible defaults
you dont need to set them like this

yea i know
okay i changed my config
on http://localhost its working with dev mode
and not working with prod mode (its ok)
i go setup my app on linux with docker, caddy web server
and start with prod mode on https
and?
i am not sure about the proxies but it should work tho
cuddy with minimal config, only for host static frontend files
what is your prod domain?
sorry i cant say
buy is subdomain
like work.domain.com
ok
we have this
__Secure
automatically applied
this is only config we have setup

here is the file if you want
https://github.com/Mail-0/Zero/blob/main/apps/server/src/lib/auth.ts
GitHub
Zero/apps/server/src/lib/auth.ts at main · Mail-0/Zero
Experience email the way you want with 0 – the first open source email app that puts your privacy and safety first. Join the discord: https://discord.gg/0email - Mail-0/Zero
@Blank Hey 🙂 Would you mind give me a hint too 🙏 Experiencing a similar issue, but:
When I set the cookie manually in Headers, using the session token as a value (received after logging in),
auth.api.getSession()
method rejects.
Do you know why? here is my config related to cookies
I work with Bruno API Client (similar to Postman). Tried via curl too..
KEY: Cookie
VALUE: myprefix.session_token=random_sesion_token
@Blank hey! you here?oh i didnt see this
whats your issue?
Im trying to test authentication with a cookie via
curl
and Postman
I use auth.api.getSession()
in my middleware to validate the session and let a user create a to-do.
this is what i send
However, it everytime fails to authenticate..
This is from my middleware
My better-auth config related to cookies:
@Blank i'm really confused..whats the error?
It just returns
null
@Blank
Have no idea why to be honest..
Okay, i made it work finally. All good, my middleware works for both bearer and a cookie.
Thanks for your help!
Enable https on your local network and you will have no errors. @Blank @M