【问题标题】:Securing a location in firebase database for one or more users to write to保护 Firebase 数据库中的一个位置,供一个或多个用户写入
【发布时间】:2017-12-18 23:39:25
【问题描述】:

我正在使用 firebase 身份验证和实时数据库构建一个新应用程序。根据文档,我了解如何保护数据库中的位置,以便只有经过身份验证的特定用户才能写入该位置:

{
"rules": {
  "users": {
    "$user_id": {
      // grants write access to the owner of this user account
      // whose uid must exactly match the key ($user_id)
      ".write": "$user_id === auth.uid"
    }
  }
}

}

我想为一位或多位用户保护一个位置。我不确定这是否可行,如果可以,我将如何构建数据。数据是一个或多个用户可以更新的购物项目列表,而所有其他用户都可以查看购物项目。所有用户都经过身份验证,但其中一个或多个被指定为购物者,因此他们可以添加和删除商品。

谢谢

克雷格

【问题讨论】:

    标签: firebase firebase-realtime-database firebase-authentication


    【解决方案1】:

    以防万一有人偶然发现这个问题,firebase 论坛的成员能够回答这个问题,我最终得到了以下数据库规则:

    {
      "rules": {
        "users": {
          ".read": "auth !== null",
          "$udser_id": {
            ".write": "$user_id === aith.uid"
          }
        },
        "shops": {
          "$shopID": {
            "items": {
              ".read": "auth != null",
              ".write": "data.parent().child('shoppers').child(auth.uid).exists()"
            },
            "shoppers": {
              ".read": "auth != null",
              ".write": "root.child('users').child(auth.uid).child('scheduler').val() == true || data.child(auth.uid).exists()"
            },
            "boxes": {
              ".read": "auth != null",
              ".write": "auth != null"
            }
          }
        }
      }
    }
    

    这是基于这里的一篇文章:https://firebase.googleblog.com/2016/10/group-security-in-firebase-database.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 2013-01-22
      相关资源
      最近更新 更多