I use express and passport in the project to work with the session and everything is fine, except for one fact. Registration and user login works perfectly, but when the user re-enters the browser, he logs out, because there is another session. Is there any good opportunity to remain logged in, even after a session change? Should I use cookies or any other packages from npm ? The usual implementation is used, with the mongodb database:
app.use(session({ secret:'secret', maxAge: new Date(Date.now() + 3600000), httpOnly: true, cookie: { path: '/', httpOnly: true, maxAge: null}, store: new MongoStore( {mongooseConnection:mongoose.connection}, function(err){ console.log(err || 'connect-mongodb setup ok'); }) })); app.use(passport.initialize()); app.use(passport.session()); It would be appreciated if there is a good example or practical advice on how this problem is solved in nodejs.
The correct view, you just had to install maxAge:
app.use(session({ secret:'secret', maxAge: new Date(Date.now() + 3600000), httpOnly: true, cookie: { path: '/', httpOnly: true, maxAge: 3600000}, store: new MongoStore( {mongooseConnection:mongoose.connection}, function(err){ console.log(err || 'connect-mongodb setup ok'); }) })); app.use(passport.initialize()); app.use(passport.session());