Open
Description
I want to set a cookie with Max-Age
only, without having Expires
. But the following lines 875-876 keep adding the unwanted Expires
:
Lines 871 to 878 in 0debedf
Setting expires: 0
does no good to override that behavior.
I think one should be allowed to only set Max-Age without automatically having Expires also set.
res.cookie('MyCookie', 'TheValue', {
expires: 0, // I don't want any Expires in the resulting Set-Cookie statement
maxAge: 60000,
});
Actual result:
MyCookie=TheValue; Max-Age=60; Path=/; Expires=Sun, 26 Mar 2023 06:00:31 GMT
Desired result:
MyCookie=TheValue; Max-Age=60; Path=/;
Workaround
The workaround for this is our having to manually write the Set-Cookie
statement, possibly mimicking the same logic in the express code.
Possible solution
if (opts.expires !== 0) {
opts.expires = new Date(Date.now() + maxAge)
}