How to delete express session cookie
req.session.destroy()
should clear the session in the db.
Express is probably using a different sessionID when trying to destroy the session. Make sure Session.prototype.destroy
is actually pulling the correct this.id
that matches the id in mongodb.sessions
.
I just came across this issue and it was because my request to the server to log out the user wasn't containing a session cookie (Had left out withCredentials
).
$.ajax({ url: 'http://url/auth/logout', type: 'GET', xhrFields: { withCredentials: true }});
This caused express to generate a new session id for the request and asked mongodb to remove a session with that new id (leaving the old one untouched).