Why session not persisted anymore after expire time?
See original GitHub issueHi, i I apologize in advance if this is a not good place to ask questions but i am cant wrap my mind around this one. I am trying to use express-session with expires time and store session with mongo, like this.
const config = require('./config/config')();
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
const express = require('express');
const app = express();
var expiryDate = new Date(Date.now() + 5 * 1000) // 10 second
app.use(session({
secret: config.secret,
store: new MongoStore({ url: config.mongo_url }),
resave: false,
saveUninitialized: false,
cookie: {
secure: process.env.NODE_ENV == 'production' ? true : false,
expires: expiryDate,
}
}));
app.use('/', function(req, res){
req.session.views = req.session.views ? req.session.views + 1 : 1;
console.log(req.session.views);
res.sendStatus(200);
});
app.listen('8080');
This code works perfectly first time. But the problem came in when the session expired. next session would not persists at all. It would be new session every time i make request. Like this:
1
2
3
4
5
6
1
1
1
Can you guys help me out?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
ASP.Net - What happend after session timeout expires
So, conclusion is that session does gets extended when users performs some activity before the timeout period. If users do some activity after ......
Read more >How to Fix Session Has Expired Error on the Internet
If your Internet connection is unstable, periodically disconnecting and reconnecting, it can cause a website session to expire. When the ...
Read more >session cookie expiration problem · Issue #670 - GitHub
Imagine a situation where you want a users session to expire, if there is no activity for 1 hour from that user anymore....
Read more >Your Session Has Timed Out - Coding Horror
Another idea: do expire the cookie after 10-15min of inactivity, but keep state persisted for a day or so, unless the user has...
Read more >Why do PHP session expire too soon on live server ... - Quora
There are various reasons why a php session doesn't last. Either: 1. The cookie expires You need to specify how long the cookies...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
On boot the
var expiryDate = new Date(Date.now() + 5 * 1000) // 10 second
is evaluated to 10s in the future. After which it is never updated, so when 10s passes all cookies should expire immediately, since the global expiryDate is in the past it will expire every time, if you’d like to test my theory you can try:Oh yes omg i am such an idiot. The cookie set is global and is not a middleware. How can i missed it? Thanks u guys so much for helping me and sorry for wasting your times haha