-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to access the current user from a model method #816
Comments
hey @bajtos , I confirmed with Rand and this solution is already explained perfectly in doc: The same example snippet as you post in comment is applied. Since it's done, I will close it here. Thanks. |
👍 |
For those looking for a solution to finding out the authenticated user in a remote method (now that currentContext is deprecated), the groundwork is laid out at the following link: http://loopback.io/doc/en/lb2/Remote-methods.html#http-mapping-of-input-arguments Here is my example snippet: MyObject.remoteMethod(
'myMethod',
{
http: {path: '/myMethod', verb: 'get'},
accepts: [
{arg: 'someArgument', type: 'string'},
{
arg: 'accessToken',
type: 'object',
http: function(ctx) {
return ctx.req.accessToken;
}
}
],
returns: {arg: 'someResponse', type: 'string'}
}
);
MyObject.myMethod = function(someArgument, accessToken, cb) {
// ...
// accessToken.userId
// ...
cb(null, "Response blah blah...");
} |
@jankcat Thank you for looking into While the link you post is from our old doc site. Now it's migrated to new site and please check latest doc of proper usage of |
Thanks, I updated my comment to the new documentation location. |
We should document the recommended way for accessing the current user from model methods.
See
And the solution:
The text was updated successfully, but these errors were encountered: