使用新值更新会话对象在帆中不起作用。
showBrowsePage: function(req, res) {
// If not logged in set `me` property to `null` and pass tutorials to the view
if (!req.session.userId) {
return res.view('browse-tutorials-list', {
me: null
});
}
User.findOne(req.session.userId, function(err, user) {
if (err) {
return res.negotiate(err);
}
if (!user) {
sails.log.verbose('Session refers to a user who no longer exists- did you delete a user, then try to refresh the page with an open tab logged-in as that user?');
return res.view('homepage', {
me: null
});
}
req.session.me = "A test value";
return res.view('browse-tutorials-list', {
me: {
email: user.email,
gravatarURL: user.gravatarURL,
username: user.username,
admin: user.admin
},
showAddTutorialButton: true
});
});
},
在这个函数调用中,尝试向会话对象“req.session.me”添加一个新值,但它没有保存在会话对象中。
res在设置值后也会发送,但仍然没有反映。