gpt4 book ai didi

loopbackjs - 设置 userContext 环回时为 NaN userId

转载 作者:行者123 更新时间:2023-12-04 18:29:31 25 4
gpt4 key购买 nike

我有一个模型 UserB2b扩展自 User .我已使用 server.authEnabled 启用授权在引导脚本中,以便所有请求都通过 auth 中间件。

问题:每当我的 UserB2b 中有一个非数字用户名时模型,我得到一个 NaN来自 AccessToken.findForRequest 的用户 ID在 loopback/common/model/access-token.js .

这是我的模型。

访问 token

{
"name": "AccessToken",
"base": "AccessToken",
"idInjection": false,
"options": {
"validateUpsert": true
},
"mysql": {
"table": "AccessToken"
},
"properties": {
"ttl": {
"type": "Number",
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "ttl",
"dataType": "int",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "Y"
},
"_selectable": true
},
"created": {
"type": "Date",
"required": false,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "created",
"dataType": "datetime",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"userId": {
"type": "String",
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "userId",
"dataType": "varchar",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 0,
"nullable": "Y"
},
"_selectable": true
},
"id": {
"type": "String",
"id": true,
"required": false,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "id",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"model": {
"type": "string",
"id": false,
"length": 100,
"precision": null,
"scale": null,
"mysql": {
"columnName": "model",
"dataType": "varchar",
"dataLength": 100,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
}
},
"validations": [],
"relations": {
"userB2B":{
"type":"belongsTo",
"model":"UserB2b",
"foreignKey":"userId"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId":"$authenticated",
"permission": "ALLOW"
}
],
"methods": {}
}

用户B2b

{
"name": "UserB2b",
"base": "User",
"idInjection": false,
"options": {
"validateUpsert": true
},
"mysql": {
"table": "user_b2b"
},
"scope": {
"where": {
"deleted": 0
}
},
"properties": {
"username": {
"type": "String",
"id": true,
"required": true,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "username",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"password": {
"type": "String",
"required": true,
"length": 1000,
"precision": null,
"scale": null,
"mysql": {
"columnName": "password",
"dataType": "varchar",
"dataLength": 1000,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"name": {
"type": "String",
"required": true,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "name",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"contactNumber": {
"type": "String",
"required": true,
"length": 255,
"precision": null,
"scale": null,
"mysql": {
"columnName": "contact_number",
"dataType": "varchar",
"dataLength": 255,
"dataPrecision": null,
"dataScale": null,
"nullable": "N"
},
"_selectable": false
},
"createdAt": {
"type": "Date",
"required": false,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "created_at",
"dataType": "timestamp",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"updatedAt": {
"type": "Date",
"required": false,
"length": null,
"precision": null,
"scale": null,
"mysql": {
"columnName": "updated_at",
"dataType": "timestamp",
"dataLength": null,
"dataPrecision": null,
"dataScale": null,
"nullable": "Y"
},
"_selectable": true
},
"deleted": {
"type": "Number",
"required": false,
"length": null,
"precision": 3,
"scale": 0,
"mysql": {
"columnName": "deleted",
"dataType": "tinyint",
"dataLength": null,
"dataPrecision": 3,
"dataScale": 0,
"nullable": "Y"
},
"_selectable": true
},
"email": false,
"created": false,
"lastUpdated": false,
"credentials": false,
"challenges": false,
"status": false,
"verificationToken": false,
"realm": false,
"emailVerified": false
},
"validations": [],
"relations": {
"accessTokens": {
"type": "hasMany",
"model": "Accesstoken",
"foreignKey": "userName"
}
},
"methods": {}
}

这是我从调试器得到的原始数据包

<-- RowDataPacket
RowDataPacket {
id: 'BJVqc7CtRXzPVVtTyJqmUabijgLRRHBe3sqcCh0bh5NuGBIZCnY8nwLIGeB6dILv',
ttl: 12096000,
created: Tue May 24 2016 05:44:18 GMT+0000 (UTC),
model: 'UserB2b',
userId: 'max1' }

然后环回触发的查询是

SELECT `username`,`password`,`name`,`contact_number`,`created_at`,`updated_at`,`deleted` FROM `user_b2b` WHERE (`username`=?) AND (`deleted`=?) ORDER BY `username` LIMIT 1, params: ["NaN",0]

这里有什么需要更正的吗?

最佳答案

您的访问 token 中似乎有问题:

"userId": {
"type": "String",
"required": false,
"length": null,
"precision": 10,
"scale": 0,
"mysql": {
"columnName": "userId",
"dataType": "int",

您使用的类型是 int 并且您作为 varchar 项传递,这将抛出字符串不是数字 (NAN) 的异常。将目标类型更改为字符串/varchar 或更改您正在使用的与目标匹配的源数据类型。

希望对您有所帮助。

关于loopbackjs - 设置 userContext 环回时为 NaN userId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37427936/

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