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
davie--1225
davie--12252mo ago
Do you use Next.js?
Bartosz Grabias
Bartosz Grabias2mo ago
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
i use arch btw.
i use arch btw.OP2mo ago
yeah, with next auth yeah. ik. the problem is that i don't know why nextauth deleting the cookie by sending Max-Age=0.
Bartosz Grabias
Bartosz Grabias2mo ago
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.

Did you find this page helpful?