In feathersjs how do I ensure my services always have the auth hook but then on specific services I can still remove it?

24 Views Asked by At

In FeathersJs I want to not have to remember to add the authenticate hook to my service methods.

I have tried to add the authenticate hook to my app hooks:

function defaultAuthentication() {
  return (context: HookContext) => {
    return authenticate('jwt')(context);
  };
}

app.hooks({
  around: {
    all: [logError],
  },
  before: { all: [defaultAuthentication()] },
  after: {},
  error: {},
});

This successfully adds the authenticate hook to all my methods.

However, I am unable to remove it for specific service methods:

app.use('healthcheck', this);
app.service('healthcheck').hooks({
  before: {
    all: [],
  },
});

This still applies the auth filter to the healthcheck end point.

0

There are 0 best solutions below