No access token available in context for "loaded" operation hook
Hi.
I'm using the "loaded" operation hook to do some final manipulations before retrieving one of my models.
The problem I'm having is that I want to get the access token for the current context but the options property is empty.
Should the current context be fully loaded automatically or is it that I'm missing an step here?
Thanks.
Sample code:
MyModel.observe('loaded', function(context, callback) {
if (context.isNewInstance) {
return callback();
}
//var accessToken = context.options.accessToken;
//context.options is an empty object
}
Doing a bit more research seems that this is the case for GET requests but not for POST/PUT.
Customizing what options returns solves the issue:
https://loopback.io/doc/en/lb3/Using-current-context.html#access-the-context-from-operation-hooks
Dispite all this I believe it would be nice if access token were available by default in the options object.
cc @bajtos
@hyperd I believe the options parameter should be set for GET requests too. Could you please share the code you are invoking via GET? Do you perhaps have a custom method that does not forward the options argument to the call of a built-in PersistedModel method?
@bajtos Sorry for the delay in replying. I think I didn't explain well. The options parameter is set correctly for GET requests. The problem is with PUT or POST requests.
I'll set up a sample project to repro this
+1
@hyperd @bajtos , I have also the same issue. but when it gets empty I am not able to figure it out clearly. BTW I am trying to pass data throughout in the application & access it. I have to hit GET request multiple time according to my application need. e.g., Person details and their Order data. Just before the person details it gets "empty". I think so.