Why is PassportJS in Node not removing session on logout

前端 未结 22 1807
有刺的猬
有刺的猬 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:03

    I'm working with a programmer, that suggests to remove user of req:

    app.get('/logout', function (req, res){
      req.session.destroy(function (err) {
        req.user = null;
        res.redirect('/'); //Inside a callback… bulletproof!
      });
    });
    

    Reason: we need to remove from req(passportjs also doing this but async way) because there is no use of user data after logout even this will save memory and also might be passportjs found user data and may create new session and redirect(but not yet happen) By the ways, this is our responsibility to remove irrelevant thing. PassportJS assign data into req.user after login and also remove if we use req.logout() but it may not works properly some times as NodeJS Asynchronous in nature

提交回复
热议问题