feathersjs 权限 - 角色

feathersjs permissions - Roles

我正在使用 feathersjs 作为网络应用程序的后端。我即将使用权限来管理对数据库的访问。

我有 3 个角色:管理员、组织者、用户

我想将每个角色的权限存储在名为 "roles" 的单独 table 中。用户有一个角色列,我想在那里存储角色 ID。

此外,每个用户只能编辑自己的行。所以我需要类似的东西:'users:update:1234' 每个用户。

如何组合它们。文档说用户 table 需要一个包含 "permissions" 的列,我可以在其中存储它们。但我想更灵活一些。

有什么好的例子吗?网上一片空白...

你好..

feathers-permissions is the way to go for this. As shown here 应该可以像这样创建您想要的动态角色:

app.service('users').hooks({
  before: checkPermissions({
    roles(context) {
      return [ `users/${context.id}` ];
    }
  })
});

现在用户必须拥有 users/123:update 权限。但是,为了限制对当前用户的请求,而不是通过 id 限制权限,可以使用 feathers-authentication-hooks