{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback/issues/1839","labels_url":"https://api.github.com/repos/strongloop/loopback/issues/1839/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback/issues/1839/comments","events_url":"https://api.github.com/repos/strongloop/loopback/issues/1839/events","html_url":"https://github.com/strongloop/loopback/issues/1839","id":119107578,"number":1839,"title":"Error fetching user model from Access Tokens","user":{"login":"robinskumar73","id":5016679,"avatar_url":"https://avatars.githubusercontent.com/u/5016679?v=3","gravatar_id":"","url":"https://api.github.com/users/robinskumar73","html_url":"https://github.com/robinskumar73","followers_url":"https://api.github.com/users/robinskumar73/followers","following_url":"https://api.github.com/users/robinskumar73/following{/other_user}","gists_url":"https://api.github.com/users/robinskumar73/gists{/gist_id}","starred_url":"https://api.github.com/users/robinskumar73/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robinskumar73/subscriptions","organizations_url":"https://api.github.com/users/robinskumar73/orgs","repos_url":"https://api.github.com/users/robinskumar73/repos","events_url":"https://api.github.com/users/robinskumar73/events{/privacy}","received_events_url":"https://api.github.com/users/robinskumar73/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback/labels/question","name":"question","color":"ededed"},{"url":"https://api.github.com/repos/strongloop/loopback/labels/triage","name":"triage","color":"eb6420"}],"state":"open","locked":false,"assignee":{"login":"Amir-61","id":10672146,"avatar_url":"https://avatars.githubusercontent.com/u/10672146?v=3","gravatar_id":"","url":"https://api.github.com/users/Amir-61","html_url":"https://github.com/Amir-61","followers_url":"https://api.github.com/users/Amir-61/followers","following_url":"https://api.github.com/users/Amir-61/following{/other_user}","gists_url":"https://api.github.com/users/Amir-61/gists{/gist_id}","starred_url":"https://api.github.com/users/Amir-61/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Amir-61/subscriptions","organizations_url":"https://api.github.com/users/Amir-61/orgs","repos_url":"https://api.github.com/users/Amir-61/repos","events_url":"https://api.github.com/users/Amir-61/events{/privacy}","received_events_url":"https://api.github.com/users/Amir-61/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2015-11-26T22:42:57Z","updated_at":"2015-11-26T22:56:03Z","closed_at":null,"body":"I am trying to get the username after a user has logged in. I've followed this example from the docs. However, when I try to access the user relation, I am unsuccessful. What am I doing wrong?\r\n\r\nBelow is some code. You can assume that my data store contains a User with the username 'foo' and password 'bar'.\r\n\r\n```\r\nUser.login(\r\n    {username: 'foo', password: 'bar'},\r\n    'user',\r\n    function(err, accessToken) {\r\n        console.log(accessToken);\r\n        // This prints out a serialization of the accessToken and\r\n        // interestingly the user is in there as well, as expected.\r\n\r\n        // But note the following:\r\n        accessToken.user(function(err, user){\r\n            console.log(err);\r\n            // null\r\n\r\n            console.log(user);\r\n            // null\r\n            // How come this is null?  Should it not be the user?\r\n        });\r\n\r\n        // After poking around with a debugger, I came across a private API\r\n        // through which I can get to the user.  But surely there must\r\n        // be a better way to do it?\r\n        console.log(accessToken.__data.user);\r\n        // This prints out a serialization of the user\r\n\r\n        console.log(accessToken.__data.user.username);\r\n        // This prints out 'foo'\r\n    }\r\n);\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback/issues/comments/160001965","html_url":"https://github.com/strongloop/loopback/issues/1839#issuecomment-160001965","issue_url":"https://api.github.com/repos/strongloop/loopback/issues/1839","id":160001965,"user":{"login":"Amir-61","id":10672146,"avatar_url":"https://avatars.githubusercontent.com/u/10672146?v=3","gravatar_id":"","url":"https://api.github.com/users/Amir-61","html_url":"https://github.com/Amir-61","followers_url":"https://api.github.com/users/Amir-61/followers","following_url":"https://api.github.com/users/Amir-61/following{/other_user}","gists_url":"https://api.github.com/users/Amir-61/gists{/gist_id}","starred_url":"https://api.github.com/users/Amir-61/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Amir-61/subscriptions","organizations_url":"https://api.github.com/users/Amir-61/orgs","repos_url":"https://api.github.com/users/Amir-61/repos","events_url":"https://api.github.com/users/Amir-61/events{/privacy}","received_events_url":"https://api.github.com/users/Amir-61/received_events","type":"User","site_admin":false},"created_at":"2015-11-26T22:56:03Z","updated_at":"2015-11-26T22:56:03Z","body":"Hi @robinskumar73,\r\n\r\nCould you please ask your question in our [Google Community](https://groups.google.com/forum/#!forum/loopbackjs)? That way people can comment on your code easily; also just a side note, [user.login](https://docs.strongloop.com/display/public/LB/Logging+in+users) returns `accessToken.userId`, by which you can query user information from the user model.\r\n\r\nI will close this ticket; please ask your question in our google community to discuss it better.\r\n\r\nThanks\r\n"}}