- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个模型 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/
我正在尝试将某种服务共享给嵌套在另一个组件中的组件,但出现未定义的错误。 'UserContext' is not defined no-undef 这是我的 App.js: import logo
我有一个模型 UserB2b扩展自 User .我已使用 server.authEnabled 启用授权在引导脚本中,以便所有请求都通过 auth 中间件。 问题:每当我的 UserB2b 中有一个非
我正在尝试创建一个可供 React 应用程序中的所有类组件访问的 UserContext。我收到以下错误。 ReferenceError: Cannot access 'UserContext' be
如何在 beforeEach() 函数中为 Jasmine 的 userContext 上的属性集提供类型? 我的代码: beforeEach(() => { this.injector =
我面临一个奇怪的问题,即在单击工具菜单下的扩展和更新时收到一条消息“值不能为空。参数名称为 userContext”。 请让我知道此问题的解决方法是什么。谢谢你。 最佳答案 我有完全相同的问题。我从开
我需要读/写 ActiveDirectory 用户对象终端服务属性。我试过这个: PrincipalContext context = new PrincipalContext(ContextType
我收到错误消息 'Value cannot be null. Parameter name: userContext' 在Visual Studio 2017中尝试单击通知或从tools文件夹中打开扩
我发现几乎每个类( Controller 、 View 、HTML 帮助程序、服务等)我都需要当前登录的用户数据。所以我考虑创建一个“环境上下文”而不是直接注入(inject) IUserServic
我是一名优秀的程序员,十分优秀!