Feathers: `hook.app` is undefined in Event filters

Created on 13 Sep 2016  路  6Comments  路  Source: feathersjs/feathers

I'm using sequelize. Here is an example scenario of when I need to use this functionality. I have users in groups. When users send a message, I need to see if they are part of that group before allowing them to see the data. GroupUsers is a mapping table mapping groups to users.

My event filter is below. If you console.log(hook.app), it logs undefined.

export default function () {
  return function filterGroupId(data, connection, hook) {
    const query = {
      userId: connection.user.id,
      groupId: data.groupId,
      deleted: false,
    };
    return hook.app.service('groupUsers').find({ query })
    .then(result => {
      if (result.total > 0) {
        return data;
      }
      return false;
    });
  };
}

All 6 comments

Your service was using this hook, i mean calling it?

Yea I have a few before and after hooks running fine before this filter happens.

Solving that issue with an member of the core development team.

https://github.com/feathersjs/feathers/pull/406

Awesome thank you.

Closed via #406

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings