From e69834e070662e8972e9eca07cbebf0338cfd226 Mon Sep 17 00:00:00 2001 From: Jared Hanson Date: Thu, 19 May 2022 08:39:31 -0700 Subject: [PATCH] Add optional options to login and logout. --- lib/http/request.js | 8 +++++++- lib/sessionmanager.js | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/http/request.js b/lib/http/request.js index 58efb3aa..9bb27e42 100644 --- a/lib/http/request.js +++ b/lib/http/request.js @@ -51,7 +51,13 @@ req.logIn = function(user, options, done) { * @api public */ req.logout = -req.logOut = function(done) { +req.logOut = function(options, done) { + if (typeof options == 'function') { + done = options; + options = {}; + } + options = options || {}; + var property = this._userProperty || 'user'; this[property] = null; diff --git a/lib/sessionmanager.js b/lib/sessionmanager.js index 0c43e5b3..30323033 100644 --- a/lib/sessionmanager.js +++ b/lib/sessionmanager.js @@ -9,7 +9,13 @@ function SessionManager(options, serializeUser) { this._serializeUser = serializeUser; } -SessionManager.prototype.logIn = function(req, user, cb) { +SessionManager.prototype.logIn = function(req, user, options, cb) { + if (typeof options == 'function') { + cb = options; + options = {}; + } + options = options || {}; + console.log('SM: logIn'); if (!req.session) { return cb(new Error('Login sessions require session support. Did you forget to use `express-session` middleware?')); } @@ -44,7 +50,13 @@ SessionManager.prototype.logIn = function(req, user, cb) { }); } -SessionManager.prototype.logOut = function(req, cb) { +SessionManager.prototype.logOut = function(req, options, cb) { + if (typeof options == 'function') { + cb = options; + options = {}; + } + options = options || {}; + console.log('SM: logOut'); if (!req.session) { return cb(new Error('Login sessions require session support. Did you forget to use `express-session` middleware?')); }