Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass new session as extra param to Session reload and regenerate callbacks #907

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ a new SID and `Session` instance will be initialized at `req.session`
and the `callback` will be invoked.

```js
req.session.regenerate(function(err) {
req.session.regenerate(function(err, session) {
// will have a new session here
})
```
Expand All @@ -363,7 +363,7 @@ Reloads the session data from the store and re-populates the
`req.session` object. Once complete, the `callback` will be invoked.

```js
req.session.reload(function(err) {
req.session.reload(function(err, session) {
// session updated
})
```
Expand Down
13 changes: 7 additions & 6 deletions session/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ defineMethod(Session.prototype, 'save', function save(fn) {

/**
* Re-loads the session data _without_ altering
* the maxAge properties. Invokes the callback `fn(err)`,
* the maxAge properties. Invokes the callback `fn(err, session)`,
* after which time if no exception has occurred the
* `req.session` property will be a new `Session` object,
* although representing the same session.
* `req.session` property and `session` callback param will be
* the new `Session` object, although representing the same session.
*
* @param {Function} fn
* @return {Session} for chaining
Expand All @@ -93,7 +93,7 @@ defineMethod(Session.prototype, 'reload', function reload(fn) {
if (err) return fn(err);
if (!sess) return fn(new Error('failed to load session'));
store.createSession(req, sess);
fn();
fn(null, req.session);
});
return this;
});
Expand All @@ -113,7 +113,8 @@ defineMethod(Session.prototype, 'destroy', function destroy(fn) {
});

/**
* Regenerate this request's session.
* Regenerate this request's session. Invokes the callback `fn(err, session)`
* with the new session object or an error if one occurred.
*
* @param {Function} fn
* @return {Session} for chaining
Expand All @@ -140,4 +141,4 @@ function defineMethod(obj, name, fn) {
value: fn,
writable: true
});
};
}
2 changes: 1 addition & 1 deletion session/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Store.prototype.regenerate = function(req, fn){
var self = this;
this.destroy(req.sessionID, function(err){
self.generate(req);
fn(err);
fn(err, req.session);
});
};

Expand Down