简体   繁体   English

环回扩展用户模型引发TypeError:无法将未定义或null转换为对象

[英]Loopback extending User model throws TypeError: Cannot convert undefined or null to object

I'm trying to extend the default User model as follows: 我正在尝试扩展默认的用户模型,如下所示:

I used the slc loopback:model cli command to create the new 'account' model (extending the built in User model with a firstName and lastName property). 我使用了slc loopback:model cli命令来创建新的“帐户”模型(使用firstName和lastName属性扩展了内置的User模型)。 It created a common/models/account.json : 它创建了common/models/account.json

{
  "name": "account",
  "base": "User",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "firstName": {
      "type": "string"
    },
    "lastName": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

and a common/models/account.js : common/models/account.js

'use strict';

module.exports = function(Account) {

}; 

also added to server/model-config.json : 还添加到server/model-config.json

  "account": {
    "dataSource": "db",
    "public": true
  }

when i try to log in on the new url, instead of a 401, I'm getting a 500 error: 当我尝试登录新网址而不是401时,出现500错误:

Unhandled error for request POST /api/accounts/login: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Memory._findAllSkippingIncludes (d:\test-api\node_modules\loopback-datasource-juggler\lib\connectors\memory.js:432:22)
    at Memory.all (d:\test-api\node_modules\loopback-datasource-juggler\lib\connectors\memory.js:506:20)
    at invokeConnectorMethod (d:\test-api\node_modules\loopback-datasource-juggler\lib\dao.js:169:21)
    at d:\test-api\node_modules\loopback-datasource-juggler\lib\dao.js:2131:7
    at doNotify (d:\test-api\node_modules\loopback-datasource-juggler\lib\observer.js:155:49)
    at d:\test-api\node_modules\loopback-datasource-juggler\lib\observer.js:168:23
    at d:\test-api\node_modules\async\dist\async.js:473:16
    at replenish (d:\test-api\node_modules\async\dist\async.js:1006:25)
    at d:\test-api\node_modules\async\dist\async.js:1016:9
    at eachLimit$1 (d:\test-api\node_modules\async\dist\async.js:3196:24)
    at Object.<anonymous> (d:\test-api\node_modules\async\dist\async.js:1046:16)
    at doNotify (d:\test-api\node_modules\loopback-datasource-juggler\lib\observer.js:157:11)
    at doNotify (d:\test-api\node_modules\loopback-datasource-juggler\lib\observer.js:155:49)
    at doNotify (d:\test-api\node_modules\loopback-datasource-juggler\lib\observer.js:155:49)
    at doNotify (d:\test-api\node_modules\loopback-datasource-juggler\lib\observer.js:155:49)

If I change the login api url to /Users/login, it returns a 401 as expected. 如果我将登录api URL更改为/ Users / login,它将按预期返回401。 Any ideas what is wrong? 任何想法有什么问题吗?

Apparently clearing out the db, and first creating a user resolved the issue. 显然清除数据库,然后首先创建用户即可解决该问题。 If no entities have been entered into the db yet, the issue exists. 如果尚未将任何实体输入数据库,则存在问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:无法将未定义或空值转换为对象 javascript - TypeError : Cannot convert undefined or null to object javascript 错误TypeError:无法将未定义或null转换为对象 - error TypeError: Cannot convert undefined or null to object Javascript:TypeError:无法将未定义或null转换为对象 - Javascript: TypeError: Cannot convert undefined or null to object 未捕获的TypeError:无法将未定义或null转换为对象 - Uncaught TypeError: Cannot convert undefined or null to object Sequelize TypeError:无法将未定义或空值转换为对象 - Sequelize TypeError: Cannot convert undefined or null to object 类型错误:无法将未定义或 null 转换为 object javascript - TypeError: Cannot convert undefined or null to object javascript 类型错误:无法将 undefined 或 null 转换为对象 - TypeError: Cannot convert undefined or null to object TypeError:无法在反应中将未定义或 null 转换为 object - TypeError: Cannot convert undefined or null to object in react $ .ajaxPrefilter引发未捕获的TypeError:无法将null转换为对象异常 - $.ajaxPrefilter throws Uncaught TypeError: Cannot convert null to object Exception TypeError:无法将undefined或null转换为object(引用Object.keys) - TypeError: Cannot convert undefined or null to object (referring to Object.keys)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM