I'm doing it like this:
app.use(express.session({
cookie:{domain:"."+settings.c.SITE_DOMAIN},
secret:'abc',
store: redis_store,
}));
When I log into my redis and type TTL sess:...
, it seems that there is an expiration on this session.
How can I make the sessions never expire? (for everything). I also want the cookies to never expire.
As mentioned in the Connect guide on the session middleware page (Express uses Connect internally), you can specify a maxAge option on sessions:
- cookie Session cookie settings, defaulting to { path: '/', httpOnly: true, maxAge: 14400000 }
Example:
connect(
connect.cookieParser()
, connect.session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }})
, connect.favicon()
, function(req, res, next){
var sess = req.session;
if (sess.views) {
res.setHeader('Content-Type', 'text/html');
res.write('<p>views: ' + sess.views + '</p>');
res.write('<p>expires in: ' + (sess.cookie.maxAge / 1000) + 's</p>');
res.end();
sess.views++;
} else {
sess.views = 1;
res.end('welcome to the session demo. refresh!');
}
}
).listen(3000);
Note: maxAge is in milliseconds, so for example a day = 86400000
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