expressjs / expressjs/session

Refreshing page bugs expire time.

Open
#259 12 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
6.4k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

I'm using the following:

``` javascript
router.use(session({
secret: 'SECRET',
resave: false,
saveUninitialized: true,
cookie: {secure: false, expires: new Date(Date.now() + config.sessionTime)}
}));
```

Where config.sessionTime is 20000.

I then have a two routes, which have the following code.

``` javascript
router.route('/session')
.get(function(req, res) {
if(req.session.views == undefined) return res.send('Your session has expired. Visit here to start a new session.');
req.session.views++;
res.send('Your session will expire in: ' + req.session.cookie.maxAge + ' (MS). You have viewed this page: ' + req.session.views + ' times.');
});

router.route('/session-start')
.get(function(req, res) {
req.session.views = 0;
res.send('Your session has started, and will expire in: ' + req.session.cookie.maxAge + ' (MS).');
});
```

Whenever I visit /session-start, to start my session then visit /session the expire time acts up whenever I refresh the page. Here's some results:
Your session will expire in: 16829 (MS). You have viewed this page: 1 times.
Your session will expire in: 17771 (MS). You have viewed this page: 4 times.
Your session will expire in: 13660 (MS). You have viewed this page: 5 times.
Your session will expire in: 18035 (MS). You have viewed this page: 8 times.

The time seems to reset everytime I refresh (so if I refresh quickly, the time left will be a greater number.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.