ember.js - 如何在 firebase auth 中设置角色?

标签 ember.js firebase emberfire

我目前正在使用电子邮件和密码登录。但我希望能够为每个用户分配一个角色:管理员或用户。我已经读到这是通过使用自定义身份验证方法完成的,但我发现文档不清楚无法使用电子邮件/密码身份验证来实现。

我将如何去设置它?

我目前正在为 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/

相关文章:

javascript - Ember.js:使当前用户全局可访问

javascript - 非常简单的 Ember 1.13.3 应用程序中的路由转换内存泄漏

javascript - 观察数组 Controller 中 ItemController 的变化

Ember.js 验收测试不等待异步数据操作

javascript - 允许首次在 Firebase 中创建数据,然后限制访问

java - 使用来自 firebase 的回收 View 和值时没有此类方法错误

ember.js - 哪种序列化器或适配器最适合在 ember js 中工作?

javascript - 如何从 Emberjs 对象中删除属性?

reactjs - firebase safari 错误消息 : This browser doesn't support the API's required to use the firebase SDK

javascript - CORS BLOCKED 'Access-Control-Allow-Origin' Firebase 功能不允许