Firebase规则auth.token.email无效:"模拟写入被拒绝"

时间:2018-04-17 12:44:47

标签: firebase-authentication

https://firebase.google.com/docs/reference/security/database/#authtokenF

{
  "rules": {
    "c":{
      ".write":"newData.child('email').val()=== auth.token.email"
    },
   }
}

始终显示"模拟写入被拒绝"
如何解决这个问题呢 ?我的firebase规则是否有任何错误

enter image description here

1 个答案:

答案 0 :(得分:1)

您似乎未在身份验证数据中提供电子邮件地址。

当您选择提供者时,模拟器会显示它将使用的确切auth.token有效负载。对于Google提供程序,我的Auth令牌有效负载如下所示:

Auth.token for Google provider

模拟器采用此处显示的文字JSON,并将其用作auth.token

{
  "provider": "google",
  "uid": "27e08474-4e33-460d-ba92-ba437c6aa962"
}

由于没有提供电子邮件,您的规则(正确)失败。

为了测试这种情况,您需要切换到自定义提供程序,以便您可以使用电子邮件属性指定自己的身份验证令牌

Custom auth.token with email property