我目前正在使用电子邮件和密码登录。但我希望能够为每个用户分配一个角色:管理员或用户。我已经读到这是通过使用自定义身份验证方法完成的,但我发现文档不清楚无法使用电子邮件/密码身份验证来实现。
我将如何去设置它?
我目前正在为 ember 使用 firebase emberfire
更新:
文档引用:https://www.firebase.com/docs/web/guide/login/custom.html
最佳答案
Firebase 刚刚通过对 ID token 的自定义用户声明启动了对任何用户基于角色的访问的支持: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 token 声明。
要从客户端上的 token 解析它,请检查:https://firebase.google.com/docs/auth/admin/custom-claims#access_custom_claims_on_the_client
关于ember.js - 如何在 firebase auth 中设置角色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36878040/