From fa70e2fb31ff92e5fc3039b0e5e8b1f67f5cd944 Mon Sep 17 00:00:00 2001 From: Jared Hanson Date: Wed, 18 May 2022 08:27:52 -0700 Subject: [PATCH] Error if session isn't available. --- lib/sessionmanager.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/sessionmanager.js b/lib/sessionmanager.js index edd2535f..c39bc6e5 100644 --- a/lib/sessionmanager.js +++ b/lib/sessionmanager.js @@ -12,6 +12,8 @@ function SessionManager(options, serializeUser) { SessionManager.prototype.logIn = function(req, user, cb) { console.log('SM: logIn'); + if (!req.session) { return cb(new Error('Login sessions require session support. Did you forget to use `express-session` middleware?')); } + var self = this; // regenerate the session, which is good practice to help @@ -25,10 +27,6 @@ SessionManager.prototype.logIn = function(req, user, cb) { if (err) { return cb(err); } - // TODO: Error if session isn't available here. - if (!req.session) { - req.session = {}; - } if (!req.session[self._key]) { req.session[self._key] = {}; }