Why is PassportJS in Node not removing session on logout

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

    I was having the same issue, and it turned out to not be a problem with Passport functions at all, but rather in the way I was calling my /logout route. I used fetch to call the route:

    (Bad)

    fetch('/auth/logout')
      .then([other stuff]);
    

    Turns out doing that doesn't send cookies so the session isn't continued and I guess the res.logout() gets applied to a different session? At any rate, doing the following fixes it right up:

    (Good)

    fetch('/auth/logout', { credentials: 'same-origin' })
      .then([other stuff]);
    

提交回复
热议问题