feathers-authentication-hooks: restrictToRoles 为具有多个角色的用户

feathers-authentication-hooks: restrictToRoles for a user with more then one role

我已经在我的项目中实现了 feathers-authentication-hooks,它正在根据包含角色的自定义用户列进行验证。现在我想让它与每个用户的多个角色一起工作。我在数据库列中尝试了几种格式,但都失败了:

数据格式(每行的确切格式): role1, role2 role1; role2 [role1,role2] {"column_name": ["role1","role2"]}

有人知道我需要做什么吗?

与阅读文档相比,该包中的大多数挂钩通常可以使用相同数量的代码和更少的时间手动实现。在这种情况下,您的示例使用这样的自定义挂钩:

const { Unauthorized } = require('feathers-errors');

return function() {
  return function(context) {
    if(context.params.user.roles.indexOf('admin') === -1) {
      throw new Unauthorized('You are not allowed to access this');
    }
  }
}