Skip to content

Refreshing page bugs expire time. #259

Open
@ghost

Description

I'm using the following:

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.

router.route('/session')
    .get(function(req, res) {
        if(req.session.views == undefined) return res.send('Your session has expired. Visit <a href="/test/session-start">here</a> 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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions