slush-marklogic-node icon indicating copy to clipboard operation
slush-marklogic-node copied to clipboard

Implement maxAge for session cookie

Open grtjn opened this issue 9 years ago • 2 comments

Session cookie never gets lost, but it would be more elegant if it timed out after for example an hour, and is kept alive as long as people use the app. Should only take a few lines of code..

grtjn avatar Oct 06 '16 13:10 grtjn

Suggested by someone:

if (!(req.path.indexOf('/api/user/') === 0 || req.path.indexOf('/app/') === 0)) {
        //Change the session so we force a new set-cookie header response with
        //the configured maxAge
        req.session._dummy = Math.random();
    }

and:

var idleTimeout = config.idleTimeout || 15 * 60 * 1000;
app.use(expressSession({
  name: 'mydemo',
  secret: '1fca4ecf-ed3b-4f1c-a644-61814347c9b1',
  cookie: {
    domain: environment === 'dev' ? undefined : '.demo.com',
    maxAge: idleTimeout // millisec
  },
  saveUninitialized: true
}));

grtjn avatar Oct 06 '16 13:10 grtjn

Also mentioned for debugging:

var debug = require('debug')('express-session');
debug('store is disconnected')

and then on commandline:

export DEBUG="express-session node server.js"

grtjn avatar Oct 06 '16 13:10 grtjn