loopbackjs - NaN userId while setting userContext loopback -
i have model userb2b
extended user
. have enabled authorization using server.authenabled
in boot script requests pass through auth middleware.
problem: whenever have non-numeric username in userb2b
model, nan
userid accesstoken.findforrequest
in loopback/common/model/access-token.js
.
here models.
accesstoken
{ "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": {} }
userb2b
{ "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": {} }
here raw packet debugger
<-- rowdatapacket rowdatapacket { id: 'bjvqc7ctrxzpvvttyjqmuabijglrrhbe3sqcch0bh5nugbizcny8nwligeb6dilv', ttl: 12096000, created: tue may 24 2016 05:44:18 gmt+0000 (utc), model: 'userb2b', userid: 'max1' }
and query loopback fires after
select `username`,`password`,`name`,`contact_number`,`created_at`,`updated_at`,`deleted` `user_b2b` (`username`=?) , (`deleted`=?) order `username` limit 1, params: ["nan",0]
is there needs corrected here ?
it seems wrong here in access token:
"userid": { "type": "string", "required": false, "length": null, "precision": 10, "scale": 0, "mysql": { "columnname": "userid", "datatype": "int",
the type using int , passing varchar item , throw exception string not number(nan). either change target type string/varchar or change source data type using matched target.
hope you.
Comments
Post a Comment