Skip to content

Commit

Permalink
Regenerate session on login.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed May 17, 2022
1 parent 5e6d92f commit 7e9b9cf
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions lib/sessionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,34 @@ function SessionManager(options, serializeUser) {
}

SessionManager.prototype.logIn = function(req, user, cb) {
console.log('SM: logIn');

var self = this;
this._serializeUser(user, req, function(err, obj) {
req.session.regenerate(function(err) {
if (err) {
return cb(err);
}
// TODO: Error if session isn't available here.
if (!req.session) {
req.session = {};
}
if (!req.session[self._key]) {
req.session[self._key] = {};
}
req.session[self._key].user = obj;
cb();

self._serializeUser(user, req, function(err, obj) {
if (err) {
return cb(err);
}
// TODO: Error if session isn't available here.
if (!req.session) {
req.session = {};
}
if (!req.session[self._key]) {
req.session[self._key] = {};
}
req.session[self._key].user = obj;
cb();
});
});
}

SessionManager.prototype.logOut = function(req, cb) {
console.log('SM: logOut');

if (req.session && req.session[this._key]) {
delete req.session[this._key].user;
}
Expand Down

0 comments on commit 7e9b9cf

Please sign in to comment.