Why is PassportJS in Node not removing session on logout

前端 未结 22 1808
有刺的猬
有刺的猬 2020-11-28 22:11

I am having trouble getting my system to log out with PassportJS. It seems the logout route is being called, but its not removing the session. I want it to return 401, if th

22条回答
  •  离开以前
    2020-11-28 23:06

    Apparently there are multiple possible causes of this issue. In my case the problem was wrong order of declarations i.e. the logout endpoint was declared before passport initialization. The right order is:

    app.use(passport.initialize());
    app.use(passport.session());
    
    
    app.get('/logout', function(req, res) {
      req.logout();
      res.redirect('/');
    });
    

提交回复
热议问题