feathers icon indicating copy to clipboard operation
feathers copied to clipboard

Skip Hooks when accessing services

Open mades5 opened this issue 1 year ago • 2 comments

Hi,

I added my own authentication strategy to feathers and have one problem with that. I authenticate my user in my strategy and try to get his rights from the database by accessing the service

const rights = await this.app?.service('rights').get(group);

This is working but the service always runs all the hooks from my service and there is a check if the user has the rights to access this service which he does not have at this point so I get an Unauthorized error. Is there a way to access a service and skipping hooks? I could not find anything about this in the documentation. Thanks

mades5 avatar Mar 13 '24 18:03 mades5

In your hook you can add a check that if there is no user to skip the auth check.

AshotN avatar Mar 13 '24 23:03 AshotN

That's not possible, the user is already there. Just the rights are missing.

mades5 avatar Mar 14 '24 01:03 mades5

// if internal call from another service
if (context.params.provider === undefined) {
    // skip checks
}

reharis avatar May 24 '24 21:05 reharis

For adapter services all their service methods can be called without hooks by using their underscored (._get, _.find etc.) methods (see https://feathersjs.com/api/databases/common.html#methods-without-hooks)

daffl avatar May 29 '24 21:05 daffl