Thursday, 15 May 2014

node.js - How to keep session in expressjs to not expire -



node.js - How to keep session in expressjs to not expire -

i have written simple cms in nodejs using expressjs framework. used passportjs authentication using twitter. below app.configure:

app.configure(function(){ //views app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); //parse request bodies app.use(express.bodyparser()); app.use(express.methodoverride()); // session back upwards app.use(express.cookieparser(cfg.cookie_secret)); app.use(express.session({ key : 'whynode', store : sessionstore, cookie: { expires: new date(date.now() + 60 * 10000), maxage: 60*10000 } })); app.use(passport.initialize()); app.use(passport.session()); //pass user info app.use(function(req, res, next) { res.locals.req_path = req.path; res.locals.user = req.user || false; next(); }); //get routers app.use(app.router); //serve asset files app.use('/assets', express.static(__dirname + '/public')); });

i used redis session store. total app.js code can viewed here full app.js experiencing when leave app unused minutes, session expires , need login again. how create session doesnot timeout atleast 2-3 hours of inactivity?

adjust code:

cookie: { expires: new date(date.now() + 60 * 10000), maxage: 60*10000 }

that sets expiry session 10 minutes. don't need utilize both maxage or expires, 1 suffice (the difference expires uses date instance , maxage means expire x milliseconds now).

node.js

No comments:

Post a Comment