Reputation: 7511
I have create a web application using sails js. Following is logout function.
logout: function(req, res) {
req.session.destroy(function(err) {
res.redirect('/');
});
}
Sometime user does not logout from one click. But anyway user is redirecting to my home page. Then I have to click again logout button to logout the user.
Upvotes: 5
Views: 4200
Reputation: 2852
Try this,
logout: function(req, res) {
// clear login sessions here
req.session.destroy(function(err) {
setTimeout(function(){
return res.redirect('/login');
}, 2500); // redirect wait time 2.5 seconds
});
}
Just giving a delay for sails js to clear the session, Working fine for me...
Upvotes: 0
Reputation: 5979
Send them to a logout page instead of a redirect or put a timeout in the callback.
logout: function(req, res) {
req.session.destroy(function(err) {
return res.view('/logout');
});
}
or
logout: function(req, res) {
req.session.destroy(function(err) {
timeout(function(){
return res.redirect('/');
}, 1000);
});
}
Upvotes: 5