每次重新加载页面时,我的快速会话都会过期(重新加载)。我正在打印创建的会话,以检查它是否已创建,我可以看到它,但重新加载后再次创建会话,因为旧的会话未定义。
const session = require("express-session");
app.enable('trust proxy');
app.use(session({
secret: "Eqg9UP323tfiP3uUuuW9ysUFMCl2289u",
resave: false,
saveUninitialized: true,
cookie: {
secure: false,
maxAge: 1000 * 60 * 60 * 24
}
}));
app.use('/', pagesRouter);
和我的路由器检查会话
router.get('/', (req, res, next) => {
const user = new Identify(req.session.identifier);
const authStatus = user.getAuthStatus();
if (authStatus == false) {
if (!req.session.identifier){ // every time undefined
req.session.identifier = user.setUserIdentifier();
req.session.save(err => {
if (!err) console.warn('New unidentified user with new token: ' + req.session.identifier);
});
} else {
}
} else {
console.log('Already authenticated user with token: ' + req.session.identifier);
}
});