-
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
Cant get current accesToken in operation hook #2871
Comments
Normally, you'd use something like this:
However, |
@fabien Is there anyway to access http request object inside an operation hook? How did you fix issues with loopback-context? I tried using cls-hooked but faced same issues as cls. I am looking for a workaround to replace loopback-context with a better mechanism. I am thinking of setting all context variables on req.context and consuming those values in other chain of functions. But I couldn't access http request object in operation hooks. Can you please guide me on these lines. It would be of a great help, Thanks. |
@vijay22sai Hello, |
@josieusa Thanks for your suggestions. I tried to use your proposed PR as mentioned here. But still it didn't solve the concurrency issue which i have been facing. Here is the code snippet to reproduce the issue. I have a /test endpoint which gets requestId in query object. this code works fine as expected at concurrency level 10.
output on console for the above code looks like below (correct output):
Now, when i replace ES6 promise with a when.js promise, context is getting messed up. At concurrency 10, only 1 or 2 requests are having original context and for other requests, context is wrong (here context is logged query). code is below.
and console looks like below (wrong output):
Please let me know if there is anything wrong in my usage, Thanks. |
@vijay22sai Thanks, I'll take a look. |
@vijay22sai I can confirm that I get the same output :( |
@josieusa, Thanks for confirming the issue. Please let me know once you created the issue so that i can keep an eye on it. Also you may know that Were you able to get correct context in operation hooks as well? Can you test that once? Thanks a lot. |
@vijay22sai Yes, I know. I linked the issue I just created. No, the only way I know to do that in operation hooks is to use my PR 11 of strongloop/loopback-context, and that is what I'm using while I wait for a proper fix (maybe refactoring my app in order to stop using operation hooks, I don't know yet). |
@josieusa Thanks for creating an issue on |
@vijay22sai Yes, I just tested for you that |
@josieusa Thank you very much 👍 . I will test it myself and update you. |
@josieusa By using your I will port to use official solution whenever it is mature and stable meanwhile I will continue using your forked version. please keep me in a loop if anything interesting is happening around this area, Thank you. |
@vijay22sai I posted an alternative solution on strongloop/loopback-context#17 |
FWIW, #3048 has been released today. I am closing this issue, please open a new one in loopback-context if there is anything more to discuss in relation to the old |
How can I get the current user in an operation hook? I've tried the guide using context vice versa but can't get it to work. Also reading that the loopback-contex is depricated.
https://docs.strongloop.com/display/public/LB/Using+current+context#Usingcurrentcontext-Configurecontextpropagation
Here is my operation hook:
Model.observe('before save', function (ctx, next) {
ctx.accessToken....
}
The text was updated successfully, but these errors were encountered: