diff --git a/lib/middleware/token.js b/lib/middleware/token.js index 6087fd31..3bfff701 100644 --- a/lib/middleware/token.js +++ b/lib/middleware/token.js @@ -51,14 +51,8 @@ function token(options) { return function (req, res, next) { if (req.accessToken !== undefined) return next(); TokenModel.findForRequest(req, options, function(err, token) { - if(err) return next(err); - if(token) { - req.accessToken = token; - next(); - } else { - req.accessToken = null; - return next(); - } + req.accessToken = token || null; + next(err); }); } } diff --git a/lib/models/access-token.js b/lib/models/access-token.js index 2171016e..9f36268b 100644 --- a/lib/models/access-token.js +++ b/lib/models/access-token.js @@ -133,7 +133,9 @@ AccessToken.findForRequest = function(req, options, cb) { } else if(isValid) { cb(null, token); } else { - cb(new Error('Invalid Access Token')); + var e = new Error('Invalid Access Token'); + e.status = e.statusCode = 401; + cb(e); } }); } else { diff --git a/lib/registry.js b/lib/registry.js index 1c48e24c..acbb7384 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -248,7 +248,7 @@ registry.memory = function (name) { if(!memory) { memory = this._memoryDataSources[name] = this.createDataSource({ - connector: loopback.Memory + connector: 'memory' }); } diff --git a/package.json b/package.json index 2f190c88..5e3756b2 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "mobile", "mBaaS" ], - "version": "1.9.0", + "version": "1.9.1", "scripts": { "test": "mocha -R spec" },