我目前正在使用电子邮件和密码登录。但我希望能够为每个用户分配一个角色:admin或user。我已经读过这是通过使用自定义身份验证方法完成的,但我发现使用电子邮件/密码身份验证无法实现文档。
我该如何设置呢?
我目前正在使用firebase for ember emberfire
更新
文档参考:https://www.firebase.com/docs/web/guide/login/custom.html
答案 0 :(得分:1)
Firebase刚刚通过ID令牌上的自定义用户声明启动了对任何用户基于角色的访问的支持:https://firebase.google.com/docs/auth/admin/custom-claims
您将定义管理员访问规则:
{
"rules": {
"adminContent": {
".read": "auth.token.admin === true",
".write": "auth.token.admin === true",
}
}
}
使用Admin SDK设置用户角色:
// Set admin privilege on the user corresponding to uid.
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.
});
这将传播到相应用户的ID令牌声明。
要从客户端上的令牌解析它,请检查:https://firebase.google.com/docs/auth/admin/custom-claims#access_custom_claims_on_the_client