You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Login should allow a full fledged include filter #1477
The workaround (it may be a lapse in my understanding) seems a bit wasteful/slow when retrieving user's related models via promise chaining after login.
For example:
If I chained UserModel.login() with UserModel.findById() ... I can't use the include filter to get the related models as the include filter isn't supported for findById
If I chain login with findOne which support include filter, it will fail due to authorization reasons ... something about loopback not being able to apply ACLs unless an id is known in the REST url.
So I'm left with one call per related model being chained like so:
{
"error":{
"name":"Error",
"status":403,
"message":"Access Denied",
"statusCode":403,
"code":"ACCESS_DENIED",
"stack":"Error: Access Denied
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/lib/application.js:348:21
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/lib/model.js:313:7
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/common/models/acl.js:465:23
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/node_modules/async/lib/async.js:251:17
at done (/Users/pulkitsinghal/dev/w2/node_modules/loopback/node_modules/async/lib/async.js:132:19)
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/node_modules/async/lib/async.js:32:16
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/node_modules/async/lib/async.js:248:21
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/node_modules/async/lib/async.js:572:34
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/common/models/acl.js:447:17
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/common/models/role.js:319:23
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/node_modules/async/lib/async.js:368:13
at done (/Users/pulkitsinghal/dev/w2/node_modules/loopback/node_modules/async/lib/async.js:132:19)
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/node_modules/async/lib/async.js:32:16
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/node_modules/async/lib/async.js:365:17
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/common/models/role.js:310:15
at /Users/pulkitsinghal/dev/w2/node_modules/loopback-datasource-juggler/lib/dao.js:1442:62
at allCb (/Users/pulkitsinghal/dev/w2/node_modules/loopback-datasource-juggler/lib/dao.js:1374:7)
at /Users/pulkitsinghal/dev/w2/node_modules/loopback-datasource-juggler/lib/connectors/memory.js:371:7
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31
at /Users/pulkitsinghal/dev/w2/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31
at process._tickDomainCallback (node.js:492:13)
at process.<anonymous> (/Users/pulkitsinghal/dev/w2/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/index.js:19:15)"
}
}
@pulkitsinghal To get include: 'roles working you need to define the relationship: User.hasMany(Role, {through: RoleMapping, foreignKey: 'principalId'});
+1
I should be able to log in and have related objects returned (using include) in a single REST call. As I understand it, I can only get the user object returned in a single call.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.
Reopening based on the discussion in #3641. Please note that this issue is not a priority to us, we are not going to work on it anytime soon. Please let us know if you can contribute this improvement yourself, we are happy to help you along the way.
in api documentation (http://apidocs.loopback.io/loopback/#user-login) it looks like this feature is there but i couldn't make it working. is it already implemented? is there any sample code?
@ahmetcetin AFAIK, it's not possible to include arbitrary related models in User.login request yet. Would you like to contribute this feature yourself?
@ahmetcetin below code is working for relational data on login. You can remove scope if you want every field from the relational data. Let me know if you have a different solution or idea.
The App-user.js returns user along with relational data. Needs node ^7.6.0
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.
Activity
pulkitsinghal commentedon Jun 23, 2015
The workaround (it may be a lapse in my understanding) seems a bit wasteful/slow when retrieving user's related models via promise chaining after login.
For example:
UserModel.login()withUserModel.findById()... I can't use theincludefilter to get the related models as theincludefilter isn't supported forfindByIdloginwithfindOnewhich supportincludefilter, it will fail due to authorization reasons ... something about loopback not being able to apply ACLs unless anidis known in the REST url.silly no?
doublemarked commentedon Jun 23, 2015
You should be using approach 2,
loginchained withfindOnew/include. I'm not sure why it's failing. Show us how you were doing it?pulkitsinghal commentedon Jun 23, 2015
@doublemarked - sure, here's what I tried for approach 2:
This works but does not have roles:
UserModel.findOne({id: $sessionStorage.currentUser.userId})It doesn't work when I try to include roles:
I think @beeman uses it here: https://github.com/beeman/loopback-angular-playground/blob/498f39b9c48c4984cedf5c574ce692c7a114247f/client/js/services/auth.js#L7-L10
I get an error:
faridnsh commentedon Aug 19, 2015
@pulkitsinghal To get
include: 'rolesworking you need to define the relationship:User.hasMany(Role, {through: RoleMapping, foreignKey: 'principalId'});pulkitsinghal commentedon Aug 19, 2015
@alFReD-NSH - Thanks! I've had that for a while: https://github.com/ShoppinPal/warehouse/blob/develop/common/models/user-model.json#L43-L48
I think it is just the way login is implemented, it doesn't do certain things. So I'd like it enhanced :)
stringbeans commentedon Aug 26, 2015
+1, would like to see the ability to include more than just the "user". it is strange that it is limited ONLY to the user and no sub relations
mamartins commentedon Feb 8, 2016
+1
lee-40square commentedon Jul 25, 2016
+1
I should be able to log in and have related objects returned (using include) in a single REST call. As I understand it, I can only get the user object returned in a single call.
dongmai commentedon Aug 12, 2016
+1
dongmai commentedon Aug 31, 2016
+1
acabreragnz commentedon Sep 7, 2016
+1
tatianacmh commentedon Sep 7, 2016
+1
mradzinski commentedon Sep 7, 2016
+1
rkmax commentedon Sep 7, 2016
+1
12 remaining items
stale commentedon Sep 6, 2017
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the
CODEOWNERSfile at the top-level of this repository.bajtos commentedon Oct 13, 2017
Reopening based on the discussion in #3641. Please note that this issue is not a priority to us, we are not going to work on it anytime soon. Please let us know if you can contribute this improvement yourself, we are happy to help you along the way.
phortonssf commentedon Oct 17, 2017
Appuser.js returns user along with relational data. Needs node ^7.6.0
ahmetcetin commentedon Nov 17, 2017
in api documentation (http://apidocs.loopback.io/loopback/#user-login) it looks like this feature is there but i couldn't make it working. is it already implemented? is there any sample code?
bajtos commentedon Dec 14, 2017
@ahmetcetin AFAIK, it's not possible to include arbitrary related models in
User.loginrequest yet. Would you like to contribute this feature yourself?ahmetcetin commentedon Dec 14, 2017
@bajtos i'll give it a try during Christmas break, till then quite busy.
phortonssf commentedon Dec 14, 2017
@ahmetcetin below code is working for relational data on login. You can remove scope if you want every field from the relational data. Let me know if you have a different solution or idea.
The App-user.js returns user along with relational data. Needs node ^7.6.0
stale commentedon Feb 12, 2018
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
stale commentedon Feb 26, 2018
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the
CODEOWNERSfile at the top-level of this repository.