gpt4 book ai didi

javascript - 环回扩展用户模型抛出 TypeError : Cannot convert undefined or null to object

转载 作者:行者123 更新时间:2023-12-03 01:24:49 25 4
gpt4 key购买 nike

我正在尝试按如下方式扩展默认用户模型:

我使用 slc Loopback:model cli 命令创建新的“account”模型(使用firstName 和lastName 属性扩展内置的User 模型)。它创建了一个 common/models/account.json:

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

和一个common/models/account.js:

'use strict';

module.exports = function(Account) {

};

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

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

当我尝试登录新网址时,我收到了 500 错误,而不是 401:

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)

如果我将登录 api url 更改为/Users/login,它会按预期返回 401。任何想法有什么问题吗?

最佳答案

显然清除数据库并首先创建用户解决了该问题。如果尚未将任何实体输入数据库,则存在问题。

关于javascript - 环回扩展用户模型抛出 TypeError : Cannot convert undefined or null to object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51595567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com