From 778395e6d5ad0626dbc507e913c3bc834d93478c Mon Sep 17 00:00:00 2001 From: ryanxwelch Date: Mon, 18 Jun 2018 15:13:39 -0400 Subject: [PATCH 1/2] fix: resolve customAccessToken warning error that causes app to crash In the present implementation verifyUserRelations(Model) sets a const hasManyTokens which seems to resolve to a boolean or undefined, so checking hasManyTokens.polymorphic throws an error. It seems the intention is to check whether the the following conditions are met: 1. a model has a hasMany accessTokens relation 2. that relation is polymorphic The proposed change should resolve correctly for any models that meet this criteria. --- lib/application.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/application.js b/lib/application.js index b597d4971..e9cbc0743 100644 --- a/lib/application.js +++ b/lib/application.js @@ -460,7 +460,7 @@ app._verifyAuthModelRelations = function() { const hasManyTokens = Model.relations && Model.relations.accessTokens; // display a temp warning message for users using multiple users config - if (hasManyTokens.polymorphic) { + if (hasManyTokens && Model.settings.relations.accessTokens.polymorphic) { console.warn( 'The app configuration follows the multiple user models setup ' + 'as described in http://ibm.biz/setup-loopback-auth', From c5cf2f1e05d0175822108e3e36697f551eca83ca Mon Sep 17 00:00:00 2001 From: ryanxwelch Date: Tue, 19 Jun 2018 12:56:17 -0400 Subject: [PATCH 2/2] refactor fix: default empty object before polymorphic check Per @bajtos recommendation https://github.com/strongloop/loopback/pull/3921#issuecomment-398307719 --- lib/application.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/application.js b/lib/application.js index e9cbc0743..840b29631 100644 --- a/lib/application.js +++ b/lib/application.js @@ -458,9 +458,10 @@ app._verifyAuthModelRelations = function() { function verifyUserRelations(Model) { const hasManyTokens = Model.relations && Model.relations.accessTokens; - + const relationsConfig = Model.settings.relations || {}; + const hasPolyMorphicTokens = (relationsConfig.accessTokens || {}).polymorphic; // display a temp warning message for users using multiple users config - if (hasManyTokens && Model.settings.relations.accessTokens.polymorphic) { + if (hasPolyMorphicTokens) { console.warn( 'The app configuration follows the multiple user models setup ' + 'as described in http://ibm.biz/setup-loopback-auth', @@ -470,7 +471,6 @@ app._verifyAuthModelRelations = function() { if (hasManyTokens) return; - const relationsConfig = Model.settings.relations || {}; const accessTokenName = (relationsConfig.accessTokens || {}).model; if (accessTokenName) { console.warn(