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
While implementing client SDKs consuming the new ACL/Auth features, we have found that client apps usually need to get details of the currently logged in user. At the moment, clients have to send two requests: User.login and User.get.
We should modify User.login so that it optionally adds the user data to the response.
Objectives
Backwards compatibility. /users/login should return the same response as before this change.
Opt-in scheme. Clients have to explicitly request the inclusion of user data.
Assume that the decision whether User.login should include user data can be made on per-application level, thus all clients should be receiving the same kind of the response.
Implementation-wise, we need to make the remoting metadata of User.login configurable.
I am also not sure if this will work out of the box with #160 (the nested User object should not include password and other sensitive data).
I was thinking about a different approach:
User.login({include: 'user'},function(err,token,user){// user is undefined when include:'user' was not specified});// remoting metadata
returns: [{arg: 'accessToken',type: 'object',root: true},{arg: 'user',type: 'object'},]
This does not work in the current implementation, but the fix should be easy. (See SharedMethod.toResult).
I have the same question. Using accessToken.__data.user as in
console.log("User: %j", accessToken.__data.user);
Did give me the json for user. But why not accessToken.user ?
I suspect the answer is:
There is one more thing we need consider: since AccessToken belongsTo User, it already has a user property of type function (see loopback-datasource-juggle/lib/relations.js#L244).
But is there better or less hackish way to do this instead of accessToken.__data.user ?
But is there better or less hackish way to do this instead of accessToken.__data.user ?
I think if the related user data has been already stored in accessToken.__data.user, then you may be able to retrieve it by calling accessToken.user(). I am not sure though. Let's move this discussion to #165 please.
Activity
ritch commentedon Jan 29, 2014
Using the existing
includesemantics forModel.find:bajtos commentedon Jan 29, 2014
An alternate solution:
Assume that the decision whether User.login should include user data can be made on per-application level, thus all clients should be receiving the same kind of the response.
Implementation-wise, we need to make the remoting metadata of User.login configurable.
AccessToken only
AccessToken + User
The implementation of User.login can stay the same, it can always send both
accessTokenanduserto the callback.bajtos commentedon Jan 29, 2014
@ritch That was the second option I wanted to mention. So the response will contain AccessToken properties +
user, is that correct?ritch commentedon Jan 29, 2014
Yep
bajtos commentedon Jan 29, 2014
BTW the solution for this won't be trivial.
The naive implementation does not work, as Model.toJSON seems to ignore custom properties.
I am also not sure if this will work out of the box with #160 (the nested User object should not include password and other sensitive data).
I was thinking about a different approach:
This does not work in the current implementation, but the fix should be easy. (See SharedMethod.toResult).
ritch commentedon Jan 29, 2014
Looks fine to me.
bajtos commentedon Jan 30, 2014
Oh well, my approach does not work either. At the end, the complex
returnsdefinition boils down to the same code being executed:result.user = user.I have found a hacky workaround (see #162 for details), which I will probably use for now:
There is one more thing we need consider: since
AccessToken belongsTo User, it already has auserproperty of type function (see loopback-datasource-juggle/lib/relations.js#L244).If
User.loginoverrides this property value then the code callingUser.logindirectly may stop working.I feel there should be a better way for exposing the
belongsTomodels in the JSON response, possibly similar to the solution in loopbackio/loopback-datasource-juggler#64. @raymondfeng could you advise?bajtos commentedon Jan 30, 2014
Let's continue the discussion about
AccessToken belongsTo Userin #165.lukewendling commentedon Sep 27, 2015
So, if I want to get the user from the access token, I should use
accessToken.__data.user?HarisHashim commentedon Sep 22, 2017
I have the same question. Using
accessToken.__data.useras inconsole.log("User: %j", accessToken.__data.user);Did give me the json for user. But why not
accessToken.user?I suspect the answer is:
But is there better or less hackish way to do this instead of
accessToken.__data.user?rahulrsingh09 commentedon Oct 5, 2017
@bajtos @ritch Loopback says include.toLowerCase is not a function\
bajtos commentedon Oct 6, 2017
@lukewendling @HarisHashim
I think if the related user data has been already stored in
accessToken.__data.user, then you may be able to retrieve it by callingaccessToken.user(). I am not sure though. Let's move this discussion to #165 please.@rahulrsingh09
I am afraid I have no idea what you are writing about. Please open a new issue and provide us with enough details to reproduce the problem you are encountering, see http://loopback.io/doc/en/contrib/Reporting-issues.html#bug-report