In express, does setting maxAge=null
in session cookie, sets the session cookie not to expire for life time?
So, to set expire time to cookies, an object with expire property can be sent which holds the expire time in milliseconds. An alternate approach to set cookie expiration age is to use optional magAge property. res. cookie(name, 'value', {maxAge : 9999});
cookie(name, 'value', {expire: 360000 + Date. now()}); Another way to set expiration time is using 'maxAge' property. Using this property, we can provide relative time instead of absolute time.
Session cookies expire once you log off or close the browser. They are only stored temporarily and are destroyed after leaving the page. They are also known as transient cookies, non-persistent cookies, or temporary cookies.
Using cookies to do stuff Cookies without an Expires or Max-Age attribute are treated as session cookies, which means they are removed once the browser is closed. Setting a value on either Expires or Max-Age makes them permanent cookies, since they will exist until they hit their expiry date.
If you don't want the session to expire, set the cookie expires date to a date far in the future:
app.use(session({
store: sessionStore,
secret: config.session.secret,
cookie: {expires: new Date(253402300000000)} // Approximately Friday, 31 Dec 9999 23:59:59 GMT
}))
See the express session docs.
If you're concerned about using a date so far in the future, try new Date(2147483647000)
(Tue, 19 Jan 2038 03:14:07 GMT, which is 2^31 - 1
in milliseconds)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With