How do I have two Express sessions?

橙三吉。 提交于 2019-12-06 14:54:09

I found the answer! Apparently I wasn't the only one having this problem: https://github.com/jaredhanson/passport/issues/244. You can read all the details there, but ...

TLDR: My client was fetch-ing /logout from the server. However by default fetch doesn't set the { credentials: 'same-origin' } option, and apparently you need to provide that or else Passport just silently starts creating duplicate sessions :(

So it turned out there was nothing wrong with my server code at all, the fix was just doing the following on the client-side:

fetch(`/logout`, { credentials: 'same-origin' });

Here's hoping the Passport people start throwing errors or warnings or something in response to this case, rather than letting their poor users boggle at the inexplicable, but common result (the comment with the answer had 15 thumbs ups).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!