From 579b9cbba17fea8be5ecb5193520ee15de5e4f54 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Fri, 26 Oct 2018 15:57:56 +0100 Subject: [PATCH 1/2] Exposed the method to customize the SessionManager object --- lib/authenticator.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/authenticator.js b/lib/authenticator.js index c0a400ca..d374eb2f 100644 --- a/lib/authenticator.js +++ b/lib/authenticator.js @@ -233,13 +233,21 @@ Authenticator.prototype.session = function session(options) { return this.authenticate('session', options); }; -// TODO: Make session manager pluggable -/* +/** + * Sets a custom SessionManager + * + * Examples: + * + * passport.sessionManager = new CustomSessionManager(); + * + * @api public + */ + Authenticator.prototype.sessionManager = function(mgr) { this._sm = mgr; return this; } -*/ + /** * Registers a function used to serialize user objects into the session. From d2d88c75ef826207b4ab7c9eeeb12292537fdce2 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 29 Oct 2018 14:14:19 +0000 Subject: [PATCH 2/2] Add test and fix styling --- lib/authenticator.js | 5 ++--- test/authenticator.test.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/authenticator.js b/lib/authenticator.js index d374eb2f..913df9a9 100644 --- a/lib/authenticator.js +++ b/lib/authenticator.js @@ -243,11 +243,10 @@ Authenticator.prototype.session = function session(options) { * @api public */ -Authenticator.prototype.sessionManager = function(mgr) { +Authenticator.prototype.sessionManager = function sessionManager(mgr) { this._sm = mgr; return this; -} - +}; /** * Registers a function used to serialize user objects into the session. diff --git a/test/authenticator.test.js b/test/authenticator.test.js index 1dd229ba..49f43ee0 100644 --- a/test/authenticator.test.js +++ b/test/authenticator.test.js @@ -7,6 +7,17 @@ const Authenticator = require('../lib/authenticator'); describe('Authenticator', () => { + + describe('#sessionManager', () => { + it('should set custom session manager', () => { + const passport = new Authenticator(); + const sessionManager = {}; + passport.sessionManager(sessionManager); + + expect(passport._sm).to.equal(sessionManager); + }); + }); + describe('#use', () => { describe('with instance name', () => { function Strategy() {