我使用Express 4.13.1和Redis作爲會話存儲。使用Redis存儲的快速會話無法創建會話
app.use(session({
store: new RedisStore,
secret: '...',
resave: false,
saveUninitialized: true
}));
它起初工作,但它沒有工作(在升級node.js後)。使用默認存儲(內存)工作正常,但使用RedisStore,會話不會被創建。這是創建會話的代碼:在那一刻
router.post('/admin/login', (req, res, next) => {
Auth.compare(...,() => {
req.session.authorized = true;
req.session.userId = id;
console.log(req.session); // It prints well. Session is created
res.redirect('/admin/main');
});
});
,會議改爲:
Session {
cookie:
{ path: '/',
_expires: null,
originalMaxAge: null,
httpOnly: true },
authorized: true,
userId: '...'}
但在此之後,未創建會話:
router.get('/admin/main', (req, res, next) => {
console.log(req.session);
...
});
打印會話:
Session {
cookie:
{ path: '/',
_expires: null,
originalMaxAge: null,
httpOnly: true }
}
我用過sessio n.save手動,但它不起作用。我錯過了什麼?
@FurkanO感謝您修復我的話。 – modernator