Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sometime sails js session does not destroy

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.

like image 437
Gayan Charith Avatar asked Mar 18 '15 04:03

Gayan Charith


1 Answers

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);
      });
}
like image 89
Meeker Avatar answered Oct 26 '22 23:10

Meeker