Skip to content

Commit 9d77ba2

Browse files
ryanxwelchbajtos
authored andcommitted
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.
1 parent 95bcf03 commit 9d77ba2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/application.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,10 @@ app._verifyAuthModelRelations = function() {
497497
function verifyUserRelations(Model) {
498498
const hasManyTokens = Model.relations && Model.relations.accessTokens;
499499

500+
const relationsConfig = Model.settings.relations || {};
501+
const hasPolyMorphicTokens = (relationsConfig.accessTokens || {}).polymorphic;
500502
// display a temp warning message for users using multiple users config
501-
if (hasManyTokens.polymorphic) {
503+
if (hasPolyMorphicTokens) {
502504
console.warn(
503505
'The app configuration follows the multiple user models setup ' +
504506
'as described in http://ibm.biz/setup-loopback-auth',
@@ -508,7 +510,6 @@ app._verifyAuthModelRelations = function() {
508510

509511
if (hasManyTokens) return;
510512

511-
const relationsConfig = Model.settings.relations || {};
512513
const accessTokenName = (relationsConfig.accessTokens || {}).model;
513514
if (accessTokenName) {
514515
console.warn(

0 commit comments

Comments
 (0)