From 9d77ba28d38541b005d39fc9d969a86f0221ac66 Mon Sep 17 00:00:00 2001 From: ryanxwelch Date: Mon, 18 Jun 2018 15:13:39 -0400 Subject: [PATCH] Fix crash in verifyUserRelations In the present implementation `verifyUserRelations(Model)` assumes that `Model.relations.accessTokens` is always set, and as a result may crash when trying to access `polymorphic` property of that relation. 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 This commit fixes the problem by accounting for the case where the accessTokens relation was not correctly set up. --- lib/application.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/application.js b/lib/application.js index 43965d3a..33239fa3 100644 --- a/lib/application.js +++ b/lib/application.js @@ -497,8 +497,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.polymorphic) { + if (hasPolyMorphicTokens) { console.warn( 'The app configuration follows the multiple user models setup ' + 'as described in http://ibm.biz/setup-loopback-auth', @@ -508,7 +510,6 @@ app._verifyAuthModelRelations = function() { if (hasManyTokens) return; - const relationsConfig = Model.settings.relations || {}; const accessTokenName = (relationsConfig.accessTokens || {}).model; if (accessTokenName) { console.warn(