0

这段简单的代码说明了问题:第二个会话没有保存。我怎样才能使这项工作?

router.post('/users/login', function (req, res) {

 var db = req.usersDb;
 var users = db.get('users');

 req.session.test = "This works";
 req.session.save();

 users.findOne({ username: req.body.username}).on('success', function (doc) { 
        console.log(doc.email); //this works
        req.session.email = doc.email; //This not working
        req.session.save(); 
 });

});
4

1 回答 1

0

将选项对象中的 express-session 'resave' 属性更改为 false 解决了该问题。

例子:

app.use(session({ genid: function(req) { return guid() }, secret: 'secret', resave: false, saveUninitialized: true }))
于 2015-11-10T22:11:52.753 回答