Firebase身份验证(多种类型的用户)

时间:2018-04-27 20:59:51

标签: reactjs firebase

我正在开发一个react.js项目,该项目从firebase进行身份验证,但我有3种不同类型的用户(超级管理员,供应商管理员,供应商员工),具有不同的权限。我如何从firebase验证他们,并了解这是我的venor管理员或供应商工作人员等????因为firebase只是验证单一类型的用户!

2 个答案:

答案 0 :(得分:2)

您可以使用自己的custom claims服务器上的Firebase管理SDK,通过Cloud Functions for Firebase控制访问权限。

使用以下方法为特定出价设置理赔服务器端:

admin.auth().setCustomUserClaims(uid, {admin: true}).then(() => {
// The new custom claims will propagate to the user's ID token the
// next time a new one is issued.
});

然后使用分隔管理员和供应商管理员内容的结构设置数据库:

/
   /admin
      /data for admins here
   /vendorAdmin
      / data for vendor admins here
   /staff
      // data for staff here, or perhaps this data is accessible to all since the admins may need access to it.

在Firebase控制台中,自定义规则以将这些位置限制为包含正确声明的人:

{
  "rules": {
    "admin": {
      ".read": "auth.token.admin === true",
      ".write": "auth.token.admin === true",
    }
    "vendorAdmin": {
      ".read": "auth.token.vendoradmin === true",
      ".write": "auth.token.vendoradmin === true",
    }
    "staff": {
      ".read": "auth.token.staff === true",
      ".write": "auth.token.staff === true",
    }
  }
}

这是一个简化的示例,因此您必须进一步对其进行自定义,以满足您的应用需求。

答案 1 :(得分:0)

您可以在数据库中维护users表,每次注册用户时,只需使用uid添加它们。

相关问题