I have Express with Passport authentication and have added session to it as below.
app.use(cookieParser()); // read cookies (needed for auth)
app.use(bodyParser()); // get information from html forms
app.set('view engine', 'ejs'); // set up ejs for templating
// required for passport
// Trust Proxy as it is behind web server.
//app.set('trust proxy', 1);
app.use(session({
secret: 'this is secret',
resave: false,
store: new MongoStore({ url: configDB.url }),
saveUninitialized: true,
cookie: { httpOnly: true, maxAge: 2419200000 }
})); // session secret
app.get("/*", function(req, res, next) {
if (typeof req.cookies['connect.sid'] !== 'undefined') { console.log(req.cookies['connect.sid']); }
next(); // call the next middleware
});
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
Not sure what the issue is, in Passport login I am setting session name as req.session.name
. It works fine if User A logged in, but when User B logs in, it doesn't create a new Session Object, but overwrites User A session object with User B including passport details. Also in browser the cookies get reset to User B, which should be obvious.