doronnahum / feathers-mongoose-casl

Easily create a Mongoose Service for Feathersjs with casl to handle what resources a given user is allowed to access
MIT License
7 stars 6 forks source link

When patching rules We get an error from Postman. #18

Closed dallinbjohnson closed 4 years ago

dallinbjohnson commented 4 years ago

server/node_modules/feathers-mongoose-casl/lib/src/hooks/cache/rulesCache.js

clearRulesFromCache: async function (hook) {
    const rulesCacheMap = rulesCache.rulesCacheMap;
    if (!rulesCacheMap) return;
    try {
      const hookType = hook.type;
      const method = hook.method;
      if (hookType === 'after' && ['patch', 'update', 'remove'].includes(method)) {
        rulesCacheMap.reset();
        hook.app.info(`feathers-mongoose-casl - rulesCache hook - remove rules from cache after ${method}`);
      }
      return hook;
    } catch (error) {
      hook.app.error('feathers-mongoose-casl - rulesCache hook error', error);
    }
  },

We put a brake point on this code: This errors out with info not being a function error.

hook.app.info(`feathers-mongoose-casl - rulesCache hook - remove rules from cache after ${method}`)

Error from Postman

{
    "name": "GeneralError",
    "message": "error hook for 'patch' method returned invalid hook object",
    "code": 500,
    "className": "general-error",
    "data": {},
    "errors": {}
}