Loopback: Included models not accessible in afterRemote hook

Created on 1 Jun 2015  路  4Comments  路  Source: strongloop/loopback

When including the user object during a login, attempting to access the user object in an afterRemote hook is not intuitive. The full object graph is evaluated when doing a console.log and in the response, but I cannot seem to find a way to access the included model with normal object syntax.

console.log(accessToken); // outputs the entire object graph

console.log(accessToken.user); 
/* outputs
{ [Function]
  getAsync: [Function],
  update: [Function],
  destroy: [Function],
  create: [Function],
  build: [Function],
  _targetClass: 'user' }
*/

I assume the user is not evaluated by the time I'm attempting to access it. Am I missing something simple? It would be intuitive to me that the entire graph is available in the afterRemote hook.

Most helpful comment

Call accessToken.toJSON().user

All 4 comments

Call accessToken.toJSON().user

Thank you @raymondfeng. This would be great to add to the docs under Querying data and the remote hooks sections.

Hi:

Do you know if upsert method is available ???

Best Regards

Was this page helpful?
0 / 5 - 0 ratings