Search code examples
loopbackjsloopback

Loopback: Passing ctx object in remotemethods


I am trying to access the ctx object in my remote method.

I have the following code:

MyModel.remoteMethod("getdetails", {
    accepts: [
        { arg: "options", type: "object", http: "optionsFromRequest" }
    ],
    http: {
        path: "/getdetails",
        verb: "get"
    },
    returns: {
        arg: "body",
        type: "object",
        root: true
    }
});
MyModel.getdetails= function( options, cb) {
   console.log(options.ctx);
};

I have added { arg: "options", type: "object", http: "optionsFromRequest" } but still I am not getting the ctx in my options. options contain only the accessToken and authorizedRules.

How can get access to ctx in remote methods? I am using loopback3.


Solution

  • Try this:

        accepts: [
        {arg: 'ctx', type: 'object', http: {source: 'context'}},
        ...