feathers.js - how to remove field payload from authentication response

Viewed 233

After POST /authentication api, the response will be like this.

{
    "accessToken": "XXXXX",
    "authentication": {
        "strategy": "local",
        "accessToken": "XXXXX",
        "payload": {
            "iat": 1616402936,
            "exp": 1616489336,
            "aud": "https://yourdomain.com",
            "iss": "feathers",
            "sub": "c15ef318-68fc-471c-9710-52f14d87abda",
            "jti": "57d103e1-c81b-4fc6-8bbe-952b74aaf8e3"
        }
    },
    "user": {
        "id": "c15ef320-68fc-471c-9710-52f14d87ccda",
        "email": "abc.abc@abc.com",
    }
}

I want to remove the payload object from above response.
How can I do that?

1 Answers

You should look into FeatherJS Hooks - https://docs.feathersjs.com/api/hooks.html

These can be used to inject logic into the API requests. Something like this should work for your example -

app.service('messages').hooks({
  after: {
    get: [
      async context => {
        delete context.authentication.payload
        return context;
      }
    ]
  }
});
Related