Skip to content

Commit

Permalink
Add option to keep session data on logout.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed May 19, 2022
1 parent a349c2b commit 17111d7
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 @@ -64,7 +64,7 @@ req.logOut = function(options, done) {
if (this._sessionManager) {
if (typeof done != 'function') { throw new Error('req#logout requires a callback function'); }

this._sessionManager.logOut(this, done);
this._sessionManager.logOut(this, options, done);
} else {
done && done();
}
Expand Down
4 changes: 4 additions & 0 deletions lib/sessionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ SessionManager.prototype.logOut = function(req, options, cb) {
if (req.session[this._key]) {
delete req.session[this._key].user;
}
var prevSession = req.session;

req.session.save(function(err) {
if (err) {
Expand All @@ -85,6 +86,9 @@ SessionManager.prototype.logOut = function(req, options, cb) {
if (err) {
return cb(err);
}
if (options.keepSessionData) {
Object.assign(req.session, prevSession);
}
cb && cb();
});
});
Expand Down

0 comments on commit 17111d7

Please sign in to comment.