-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
If both User and AccessToken are extended, login fails with:
<project dir>/node_modules/loopback/common/models/user.js:105
this.accessTokens.create({
^
TypeError: Cannot read property 'create' of undefined
at ModelConstructor.User.createAccessToken (<project dir>/node_modules/loopback/common/models/user.js:105:22)
at <project dir>/node_modules/loopback/common/models/user.js:261:22
at <project dir>/node_modules/loopback/common/models/user.js:319:9
at <project dir>/node_modules/loopback/node_modules/bcryptjs/dist/bcrypt.js:261:17
at <project dir>/node_modules/loopback/node_modules/bcryptjs/dist/bcrypt.js:1198:21
at Immediate.next (<project dir>/node_modules/loopback/node_modules/bcryptjs/dist/bcrypt.js:1078:21)
at Immediate._onImmediate (<project dir>/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31)
at processImmediate [as _immediateCallback] (timers.js:383:17)<project dir>/common/models/customer.json:
{
"name": "Customer",
"plural": "customers",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"customerAccessTokens": {
"type": "hasMany",
"model": "CustomerAccessToken",
"foreignKey": "userId",
"options": {
"disableInclude": true
}
}
},
"acls": [],
"methods": {}
}<project dir>/common/models/customer-access-token.json:
{
"name": "CustomerAccessToken",
"base": "AccessToken",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"customer": {
"type": "belongsTo",
"model": "Customer",
"foreignKey": "userId"
}
},
"acls": [],
"methods": {}
}<project dir>/server/model-config.json:
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"loopback/server/mixins",
"../common/mixins",
"./mixins"
]
},
"ACL": {
"dataSource": "db",
"public": false
},
"RoleMapping": {
"dataSource": "db",
"public": false
},
"Role": {
"dataSource": "db",
"public": false
},
"Customer": {
"dataSource": "db",
"public": true
},
"CustomerAccessToken": {
"dataSource": "db",
"public": false
}
}If the default entry for AccessToken is not removed from model-config.json, login works but ignores CustomerAccessToken. The issue affects both LoopBack 2.x and 3.x and is possibly related to #398 and #1450.
miguelmota