diff --git a/index.js b/index.js index e7cc383f..9b55ccc4 100644 --- a/index.js +++ b/index.js @@ -168,6 +168,7 @@ function session(options) { return function session(req, res, next) { // self-awareness if (req.session) { + debug('re-using existing session') next() return } @@ -295,13 +296,13 @@ function session(options) { if (shouldDestroy(req)) { // destroy session - debug('destroying'); + debug('destroying session') store.destroy(req.sessionID, function ondestroy(err) { if (err) { setImmediate(next, err); } - debug('destroyed'); + debug('session destroyed') writeend(); }); @@ -332,13 +333,13 @@ function session(options) { return writetop(); } else if (storeImplementsTouch && shouldTouch(req)) { // store implements touch method - debug('touching'); + debug('touching session') store.touch(req.sessionID, req.session, function ontouch(err) { if (err) { setImmediate(next, err); } - debug('touched'); + debug('session touched') writeend(); }); @@ -350,6 +351,7 @@ function session(options) { // generate the session function generate() { + debug('generating session') store.generate(req); originalId = req.sessionID; originalHash = hash(req.session); @@ -389,10 +391,17 @@ function session(options) { _reload.call(this, rewrapmethods(this, callback)) } - function save() { + function save(callback) { debug('saving %s', this.id); savedHash = hash(this); - _save.apply(this, arguments); + _save.call(this, function (err) { + if (err) { + return callback(err) + } + + debug('session saved') + callback.apply(this, arguments) + }); } Object.defineProperty(sess, 'reload', {