Cookie deleting immediately after setting
When I sign in, it responds with a Set-Cookie in the HTTP Headers. So, it ofc sets the cookie. Then, the next time my code runs something that calls
/api/auth/session
, the request responds with a set-cookie
with Max-Age=0
, deleting the cookie. Why is it deleting the cookie?4 Replies
Do you use Next.js?
Max-Age=0 will expire the cookie immediately. You cannot set infinitely-long cookies. If you're looking to set a session cookie then omit Max-Age and Expires attributes.
You way also want to send "Path=/", but I'm not 100% sure on that.
You can see all the attributes documented on MDN: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie
yeah, with next auth
yeah. ik. the problem is that i don't know why nextauth deleting the cookie by sending
Max-Age=0
.Ah, can't help with that. But I would just look at the code, see why it does what it does.
I would guess the docs also can help, though my presonal default is to just read the code.