From 07a04b71da1a87e3bb5e58b6bbf41d88256a56e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 31 Aug 2016 15:21:39 +0200 Subject: [PATCH 1/2] app.enableAuth: correctly detect attached models Fix a typo in "app.enableAuth" that caused the method to not detect the situation when e.g. the built-in User model is already attached to a datasource. --- lib/application.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/application.js b/lib/application.js index f5df7871..61015f3b 100644 --- a/lib/application.js +++ b/lib/application.js @@ -327,8 +327,10 @@ app.enableAuth = function(options) { g.f('Authentication requires model %s to be defined.', m)); } - if (m.dataSource || m.app) return; + if (Model.dataSource || Model.app) return; + // Find descendants of Model that are attached, + // for example "Customer" extending "User" model for (var name in appModels) { var candidate = appModels[name]; var isSubclass = candidate.prototype instanceof Model; From bc10d68c541839ca75ef8db2612dc96320bef59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 31 Aug 2016 15:23:48 +0200 Subject: [PATCH 2/2] test/user: don't attach User model twice --- test/user.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/user.test.js b/test/user.test.js index 0ac361bf..c638f41b 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -66,7 +66,6 @@ describe('User', function() { app.enableAuth({ dataSource: 'db' }); app.use(loopback.token({ model: AccessToken })); app.use(loopback.rest()); - app.model(User); User.create(validCredentials, function(err, user) { if (err) return done(err);