-
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
Loosing context after external request #1177
Comments
Have you set the remoting context setting as here. If so, then this is likely a bug. |
Yes, I have this setting. |
Context is within a domain of each request so each request has its own context. Additional request should not overwrite the others. If there is no request there is no context to create. How exactly are you trying to use it. Maybe I am just misunderstanding your use case. Can you provide some example code? |
@BerkeleyTrue , thanks for your response! Here is the simplified code:
|
Yes, that seems like a bug. The domain for the fetchUser callback should be the same as the domain for cardDetails callback. It may also be that the callback for thirdPartyService is loosing the domain since it's outside of loopback? Not sure on that one. Will need a Strongloop Dev or someone more familiar with Domains to chime in here. Here is a quick work around for you. var loopback = require('loopback'),
thirdPartyService = require('thirdPartyService');
module.exports = function(User) {
User.cardDetails = function(callback) {
var userId = loopback.getCurrentContext().get('user').id;
// Now userId is in the closure for this function.
// Fetch user data
thirdPartyService.fetchUser({
userId: userId
}, function(error, user) {
if (error) throw error;
// Fetch card details
thirdPartyService.fetchCard({
cardId: user.default_card,
userId: userId
}, function(error, card) {
if (error) throw error;
// Respond with card data
callback(null, card);
})
})
};
User.remoteMethod('cardDetails', {
http: { path: '/cardDetails', verb: 'get' }
});
} |
Unfortunately it does not work for model hooks, that called after external request. |
Do anybody have suggestions why context gets null after external http request? |
Can you provide a link to a test project on Github? See https://github.com/strongloop/loopback/wiki/Issues#bug-report |
getCurrentContext is deprecated: #1676 but I am not sure if it is related to your case, so if you are still running into the same issue, can you please provide a link to your test project to reproduce? Thanks. |
@loay , thanks for information.
You can view my fix here, where I'm looking data through all available contexts. |
In external request callback loopback.getCurrenrContext() returns 'null'.
Is this an expected behavior?
The text was updated successfully, but these errors were encountered: