Skip to content

Commit

Permalink
Add option to keep session data.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed May 19, 2022
1 parent e69834e commit a349c2b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/http/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ req.logIn = function(user, options, done) {
if (typeof done != 'function') { throw new Error('req#login requires a callback function'); }

var self = this;
this._sessionManager.logIn(this, user, function(err) {
this._sessionManager.logIn(this, user, options, function(err) {
if (err) { self[property] = null; return done(err); }
done();
});
Expand Down
4 changes: 4 additions & 0 deletions lib/sessionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SessionManager.prototype.logIn = function(req, user, options, cb) {
if (!req.session) { return cb(new Error('Login sessions require session support. Did you forget to use `express-session` middleware?')); }

var self = this;
var prevSession = req.session;

// regenerate the session, which is good practice to help
// guard against forms of session fixation
Expand All @@ -33,6 +34,9 @@ SessionManager.prototype.logIn = function(req, user, options, cb) {
if (err) {
return cb(err);
}
if (options.keepSessionData) {
Object.assign(req.session, prevSession);
}
if (!req.session[self._key]) {
req.session[self._key] = {};
}
Expand Down

0 comments on commit a349c2b

Please sign in to comment.