0

我有带 Passport 身份验证的 Express 并已向其添加会话,如下所示。

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

不确定问题是什么,在 Passport 登录中我将会话名称设置为req.session.name. 如果用户 A 登录它可以正常工作,但是当用户 B 登录时,它不会创建新的会话对象,而是用用户 B 覆盖用户 A 会话对象,包括护照详细信息。同样在浏览器中,cookie 被重置为用户 B,这应该是显而易见的。

4

0 回答 0