lefnire/derby-auth — pull request #31 by richtera (2013-03-24 03:18:19+00:00)
Title: When using passport.authenticate within server side code _loginUser leaves a transaction

When using a model within a server side route using passport.authenticate the _loginUser function leaves an uncommitted transaction without a local callback. Any model usage within the done routine will get stuck due to this.

Here is an example of a server side route

```javascript
expressApp.post('/api',
function (req, res, next) {
function loginError() {
res.send({error:'unable to log in'});
}
var header = req.headers.authorization;
if (header) {
var infos = header.split(" ");
if (infos[0] !== 'Basic') { return loginError(); }
if (infos[1]) {
var user = (new Buffer(infos[1], 'base64')).toString('utf8').split(":");
if (!req.body) req.body = {};
req.body.username = user[0];
req.body.password = user[1];
}
}
passport.authenticate('local', function (err, user, info) {
console.log(err, user, info);
res.contentType = 'application/json';
if (err) { return res.send({error:err.message}); }
if (!user) { return loginError(); }
var model = req.getModel();
var q = model.query("modelname").queryName(req.body.param);
q.fetch(function (err, matters) {
if (err) { return res.send({error:err.message}); }
var result = {error:null, data:[]};
if (matters) {
matters.get().forEach(function (item) {
result.data.push(item);
});
}
res.send(result);
});
```

This will just hang since the fetch completion will not occur due to the pending transaction.
By changing _loginUser to call done within the mutator completion of the setter solves the problem.