在monk的findOne命令中创建会话

时间:2015-11-10 17:24:20

标签: node.js express monk express-session

这段简单的代码说明了问题:第二个会话没有保存。我怎样才能做到这一点?

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(); 
 });

});

1 个答案:

答案 0 :(得分:0)

将options对象中的express-session'resave'属性更改为false可以解决问题。

示例:

app.use(session({ genid: function(req) { return guid() }, secret: 'secret', resave: false, saveUninitialized: true }))