feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.97k stars 742 forks source link

Skip Hooks when accessing services #3445

Closed mades5 closed 1 month ago

mades5 commented 3 months ago

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

AshotN commented 3 months ago

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

mades5 commented 3 months ago

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

haris2k commented 1 month ago
// if internal call from another service
if (context.params.provider === undefined) {
    // skip checks
}
daffl commented 1 month ago

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)