loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Cannot access 'req' object in mixin

Open vasanthps-rm opened this issue 10 years ago • 2 comments

Hello,

I have a mixin that looks somewhat like this:-

Model.updateLog = function(ctx, next) {
    console.log(ctx.req); //undefined
};
Model.observe('before save', function(ctx, next) {
    Model.updateLog(ctx, next);
});

Is there any other way to access the 'req' object? I don't want to use the 'currentContext' feature available in loopback

Thanks

vasanthps-rm avatar May 02 '16 12:05 vasanthps-rm

Hi @vasanthps-rm , you can try to use the remote hooks to get the req object

Model.updateLog = function(ctx, next) {
    console.log(ctx.req); 
    next();
};


Model.beforeRemote('**', function(ctx, next) {
    Model.updateLog(ctx, next);
});

davidcheung avatar May 06 '16 15:05 davidcheung

Also please note that we would like to encourage users to post questions on our Google Forums as we only accept bug reports and feature requests through Github issues, closing this issue, please feel free to reopen.

davidcheung avatar May 06 '16 18:05 davidcheung