Skip to content

Commit

Permalink
fix(sessions): make user cookie persistant (#209)
Browse files Browse the repository at this point in the history
Problem: User needed to login again, everytime they restarts their browser. (including Openwhyd's iOS and Electron apps)

This fix specifies a `maxAge` for cookies, so that they don't become browser-session-based by default.
  • Loading branch information
adrienjoly committed Jul 14, 2019
1 parent dc2775f commit bba528d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@ function makeMongoUrl(params) {
}

function start() {
var myHttp = require('./app/lib/my-http-wrapper/http');
const myHttp = require('./app/lib/my-http-wrapper/http');
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
const sessionMiddleware = session({
secret: process.env.WHYD_SESSION_SECRET.substr(),
store: new MongoStore({
url: makeMongoUrl(params),
ttl: 60 * 60 * 24 * 365 // 1 year
url: makeMongoUrl(params)
}),
name: 'whydSid',
maxAge: 365 * 24 * 60 * 60 * 1000, // cookies expire in 1 year (provided in milliseconds)
resave: false, // required, cf https://www.npmjs.com/package/express-session#resave
saveUninitialized: false // required, cf https://www.npmjs.com/package/express-session#saveuninitialized
});
Expand Down

0 comments on commit bba528d

Please sign in to comment.