feathers-hooks-common: disable hook seems to have wrong true/false logic
Code here means to disable when the result is false, not to disable when the result is true.
if (typeof realm === 'function') {
return function (hook) {
const result = realm(hook);
const update = check => {
if (!check) {
throw new errors.MethodNotAllowed(`Calling '${hook.method}' not allowed. (disable)`);
}
};
}
But in docs here it seems to be opposite logic:
// Disable the remove hook if the user is not an admin
remove: hooks.disable(function(hook) {
return !hook.params.user.isAdmin
})
Either the doc or the code is wrong. I guest it’s the code which is wrong.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (9 by maintainers)
https://github.com/feathersjs/feathers-hooks-common/pull/108
The
disableMethodhook deprecatesdisablein feathers-hooks-common v3.I suggest we create another hook that works like
disablebut with the correct sense. We can wean people away fromdisableby stressing the new hook in docs and maybe adding a deprecated message.Any suggestions for the name of the replacement hook?
p.s. I’ve suggested something similar be done with the
removehook which is a no-op for calls made by the server. I’ve suggesteddeleteas the name of that replacement hook.Thanks for your example. I assume it should be
if (check) {but let me ask what the ramifications might be regarding changing the code.As an aside, a number of hooks, like disable, allow their last param to be a function. This function indicates if the hook should be run or not. That feature will be deprecated in all these hooks and removed in the future.
I recommend you use
hooksCommon.iff(condition, hook)where condition may be sync, or async using a Promise.iff(condition, hook1, hook2, ...)will be supported in the future.