I want to expire the session after 1 min of inactivity. I tried the following
app.use(session({
secret: config.sessionSecret,
cookie: { maxAge: 60000 },
store: new mongoStore({
db: db.connection.db,
collection: config.sessionCollection
})
}));
The session is expiring exactly after 1 min the user logs in even if the user continues to use the application. I have been unable to set it to expire after 1 min of inactivity. Any ideas? Thanks in advance again.
I'm not sure if you've resolved your issue but I had the same issue and I'd like to post what fixed it here in case it can benefit anyone.
It seems that the default expires will end the session after the specified length of time regardless of what the user is doing but if you include resave and rolling variables it will only expire after it has been idle for the specified length of time.
var express = require("express");
var session = require("express-session");
var app = express();
app.use (
session ({
secret: "53cr3t50m3th1ng",
resave: true,
rolling: true,
saveUninitialized: false,
cookie: {
expires: 30 * 1000
}
})
);
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