From 294f22c4d9b9b8f6e1b80d4045fbf7bd4ec1e4d9 Mon Sep 17 00:00:00 2001 From: Jared Hanson Date: Thu, 19 May 2022 07:24:21 -0700 Subject: [PATCH] Better session detection and exceptions. --- lib/sessionmanager.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/sessionmanager.js b/lib/sessionmanager.js index c39bc6e5..0c43e5b3 100644 --- a/lib/sessionmanager.js +++ b/lib/sessionmanager.js @@ -47,12 +47,14 @@ SessionManager.prototype.logIn = function(req, user, cb) { SessionManager.prototype.logOut = function(req, cb) { console.log('SM: logOut'); + if (!req.session) { return cb(new Error('Login sessions require session support. Did you forget to use `express-session` middleware?')); } + var self = this; // clear the user from the session object and save. // this will ensure that re-using the old session id // does not have a logged in user - if (req.session && req.session[this._key]) { + if (req.session[this._key]) { delete req.session[this._key].user; }