【问题标题】:How Can i Write This Firebase Rule?我该如何编写这个 Firebase 规则?
【发布时间】:2017-09-20 21:39:47
【问题描述】:

这是我的数据结构

"Users": {
  "userId" : {
    "email" : "xxxx@gmail.com",
    "points" : 50,
    "subscriber" : false
  }
}

这是我指定的当前规则

"User":{
  "$uid": {
    ".read": "$uid == auth.uid",
    ".write": "auth != null"
   }
}

使用该规则 ^^ 它允许我写信给"User" 参考,但我想要的是

"User":{
  "$uid": {
     ".read": "$uid == auth.uid",
     ".write": "$uid == auth.uid"
   }
}

但是这条规则 ^^ 不允许我写信给"User" 参考,这意味着我什至不能创建一个不更新它的参考。

我尝试使用

"User":{
".write": "auth != null" // << -- this line overrode the entire children
  "$uid": {
    ".read": "$uid == auth.uid",
    ".write": "$uid == auth.uid"
   }
}

本质上,我正在寻找一种方法让经过身份验证的用户写入"User" 参考,但只有匹配uid 的经过身份验证的用户才能读取和更新uid 节点。

【问题讨论】:

    标签: android firebase firebase-realtime-database firebase-security


    【解决方案1】:

    使用这个:

    {
      "rules": {
        "users": {
          "$user_id": {
            ".write": "$user_id === auth.uid"
          }
        }
      }
    

    【讨论】:

    • Firebase 数据库安全规则中===== 没有区别。
    • @FrankvanPuffelen 我知道 !== 和 != 是一样的,那么 === 和 == 也一样?
    • 据我所知,是的。
    • 谢谢@josedlujan,我现在就试试
    • 感谢@FrankvanPuffelen 的编辑。您在大多数与 Firebase 相关的问题上都提供了帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-17
    相关资源
    最近更新 更多