Why is PassportJS in Node not removing session on logout

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

    This is still an issue.

    What I did was to use req.session.destroy(function (err) {}); on the server side and on the client side, whenever they logout:

    const logout = () => {
        const url = '/users/logout'
        fetch(url)
        setTimeout(function () {
          location.reload();    }, 500);
    

    That way, when refreshing the page, the user is without session. Just make sure you are redirecting to the correct page if no one is authenticated.

    Not the best approach, perhaps, but it works.

提交回复
热议问题