Reputation:
I have 2 functions(authenticate, restrictAccess) in the before hook (get) and i want to chain them together.But the restrictAccess is being executed twice(by the second round it has lost the context) When i remove the authenticate , the restrictAccess works as expected.
Here is my hook
module.exports = {
before: {
all: [],
get: [authenticate('jwt'), restrictAccess()],
....
But when i remove authenticate as this
module.exports = {
before: {
all: [],
get: [ restrictAccess()],
....
restrictAccess works as expected
Upvotes: 0
Views: 215
Reputation: 37
The only reason I could think of is that you maybe using the hooks on the users-service.
If this is the case the authenticate-hook probably internally calls the user service to set params.user to the requesting user, which would cause the two calls for the restrictAccess-hook.
A possible fix would be to ignore all internal calls in your restrictAccess-hook:
module.exports = context => {
if (context.params && context.params.provider) {
// put restriction logik here....
}
return context;
}
Upvotes: 2