Open TurtIeSocks opened 1 year ago
I suspect the problem is actually in your code (the logout route):
router.get('/logout', (req, res) => {
// Had to call both of these for some reason to get the session to actually be logged out correctly
req.logout((err) => {
if (err) log.error(HELPERS.auth, 'Unable to logout', err)
})
req.session.destroy() // removing this with 3.0.0 makes the error go away
res.redirect('/')
})
The req.logout
method provided by passport calls req.session.regenerate
provided by express session which calls req.session.destroy
. So there is a race condition here because you call req.logout then also req.session.destroy. Removing the second req.session.destroy is the correct solution.
Changing the above code block to:
router.get('/logout', (req, res) => {
req.logout((err) => {
if (err) {
log.error(HELPERS.auth, 'Unable to logout', err)
}
// Logout failed or successful. In either case, redirect the user.
res.redirect('/')
})
})
Should resolve the passport related error and also the inconsistent logout behavior that you described.
This might not be an actual bug, or could be an issue with Passport, but I'm experiencing this inconsistent behavior after updating this lib, so I'm starting here first.
Problem:
When a user calls the
/auth/logout
route, the server errors. It was working previously on2.1.6
, but after recently updating and changing the implementation, the same code now crashes.Version:
I recently upgraded from
^2.1.6
to^3.0.0
.Related Libs:
Error
Stack Trace
The property that is undefined is the request.
Codeblock from Passport.js
Code
Logout Route
Old Session Store
New Session Store
Solutions
So far these have appeared to "solve" the problem, but given the inconsistency, maybe something in the lib needs to be adjusted?
request.destroy()
callThank you! I've been using your library in my OSS projects for several years and it's been great :)