Why is PassportJS in Node not removing session on logout

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

    Destroying session by yourself looks weird. I faced with this issue having next configuration:

    "express": "^4.12.3",
    "passport": "^0.2.1",
    "passport-local": "^1.0.0",
    

    I should say that this configuration works well. The reason of my issue was in custom sessionStore that I defined here:

    app.use(expressSession({
        ...
        store: dbSessionStore,
        ...
    }));
    

    To be sure that your issue here too just comment store line and run without session persisting. If it will work you should dig into your custom session store. In my case set method was defined wrong. When you use req.logout() session store destroy() method not invoked as I thought before. Instead invoked set method with updated session.

    Good luck, I hope this answer will help you.

提交回复
热议问题