我正在做一个react.js项目,它可以通过防火墙进行身份验证,但我有3种不同类型的用户(超级管理员、供应商管理人员、供应商工作人员)拥有不同的权限。我如何从防火墙验证他们,并知道这是我的venor管理员或供应商的工作人员等?因为firebase只是对单一类型的用户进行身份验证!
发布于 2018-04-27 22:03:23
您可以在您自己的Firebase的云功能服务器上使用Firebase通过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",
}
}
}这是一个简化的例子,因此您将不得不进一步定制它,以满足您的应用程序的需要。
发布于 2018-04-27 21:16:44
您可以在数据库中维护一个users表,每次您注册一个用户时,也可以使用uid在那里添加它们。
https://stackoverflow.com/questions/50070240
复制相似问题