Once a js session doesn’t destroy sails

I created a web application using sails js. The following is the logout function.

logout: function(req, res) {
      req.session.destroy(function(err) {
           res.redirect('/');
      });
}

When the user does not exit from one click. But in any case, the user is redirected to my home page. Then I have to press the logout button again to logout.

+4
source share
2 answers

Send them to the logout page instead of redirecting them 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);
      });
}
+4
source

Try it,

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 js sails to clear the session, working well for me ...

0
source

All Articles