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.
This commit is contained in:
ryanxwelch 2018-06-18 15:13:39 -04:00 committed by Miroslav Bajtoš
parent 95bcf035a8
commit 9d77ba28d3
No known key found for this signature in database
GPG Key ID: 6F2304BA9361C7E3
1 changed files with 3 additions and 2 deletions

View File

@ -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(