Skip to content

Commit

Permalink
Fix crash when using sessionless requests over WebSockets.
Browse files Browse the repository at this point in the history
When disabling sessions for individual requests, it's done by deleting
the session field from the request. (See
balderdashy#841).

Unfortunately, the REST-over-WebSocket code assumed that the session was
always there. This patch checks for the existence of req.session before
calling req.session.save.
  • Loading branch information
leedm777 committed Aug 12, 2014
1 parent 444d34b commit 42bc9fd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/hooks/sockets/lib/interpreter/saveSessionAndThen.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ module.exports = function saveSessionAndThen(req, sails, cb) {
return function saveSession () {
var ctx = this,
args = Array.prototype.slice.call(arguments);

req.session.save(function (err) {
var next = function (err) {
if (err) {
sails.log.error('Session could not be persisted:',err);
}
cb.apply(ctx,args);
});
};

// If we have a session on the request, save it
// Otherwise, process the callback on the next tick
if (req.session) {
req.session.save(next);
} else {
process.nextTick(next);
}
};
};

0 comments on commit 42bc9fd

Please sign in to comment.