Skip to content

Commit

Permalink
Expose sessionManager on req, and use it rather than _passport.instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Dec 15, 2021
1 parent 6099318 commit f411118
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/http/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ req.logIn = function(user, options, done) {
if (typeof done != 'function') { throw new Error('req#login requires a callback function'); }

var self = this;
this._passport.instance._sm.logIn(this, user, function(err) {
this.sessionManager.logIn(this, user, function(err) {
if (err) { self[property] = null; return done(err); }
done();
});
Expand All @@ -57,7 +57,7 @@ req.logOut = function() {

this[property] = null;
if (this._passport) {
this._passport.instance._sm.logOut(this);
this.sessionManager.logOut(this);
}
};

Expand Down
3 changes: 3 additions & 0 deletions lib/middleware/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ module.exports = function initialize(passport, options) {
req.isAuthenticated = IncomingMessageExt.isAuthenticated;
req.isUnauthenticated = IncomingMessageExt.isUnauthenticated;

// expose session manager
req.sessionManager = passport._sm;

if (options.userProperty) {
req._userProperty = options.userProperty;
}
Expand Down
5 changes: 5 additions & 0 deletions test/http/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ describe('http.ServerRequest', function() {
req.isUnauthenticated = request.isUnauthenticated;
req._passport = {};
req._passport.instance = passport;
req.sessionManager = passport._sm;
req.session = {};

var error;
Expand Down Expand Up @@ -246,6 +247,7 @@ describe('http.ServerRequest', function() {
req.isUnauthenticated = request.isUnauthenticated;
req._passport = {};
req._passport.instance = passport;
req.sessionManager = passport._sm;
req.session = {};
req._userProperty = 'currentUser';

Expand Down Expand Up @@ -296,6 +298,7 @@ describe('http.ServerRequest', function() {
req.isUnauthenticated = request.isUnauthenticated;
req._passport = {};
req._passport.instance = passport;
req.sessionManager = passport._sm;
req.session = {};
req.session['passport'] = {};

Expand Down Expand Up @@ -378,6 +381,7 @@ describe('http.ServerRequest', function() {
req.user = { id: '1', username: 'root' };
req._passport = {};
req._passport.instance = passport;
req.sessionManager = passport._sm;
req.session = {};
req.session['passport'] = {};
req.session['passport'].user = '1';
Expand Down Expand Up @@ -409,6 +413,7 @@ describe('http.ServerRequest', function() {
req._passport = {};
req._passport.instance = passport;
req._userProperty = 'currentUser';
req.sessionManager = passport._sm;
req.session = {};
req.session['passport'] = {};
req.session['passport'].user = '1';
Expand Down

0 comments on commit f411118

Please sign in to comment.