alvin77 (16) [Avatar] Offline
#1
I created a login and logout controller action following the examples in Chapter 9.

My login function contains a req.session.userId, like this:

success: function () {

req.session.userId = createdUser.id;

return res.json(createdUser);
},
While logout is:

logout: function(req, res) {

if (!req.session.userId) {
return res.redirect('/');
};

User.findOne({id: req.session.user.id}, function (err, createdUser) {

if (err) return res.negotiate(err);
if (!createdUser) {
sails.log.verbose('Session refers to a user who no longer exists.');
res.redirect('/');
}

req.session.userId = null;
return res.redirect('/');
});
},

If I log on console I get the right value of req.session.userId only for login.
In logout req.session.userId is always 'undefined'.

How can i get the right value of req.session.userId in logout?

Thank you