Firebase:允许读取属性名称,但不允许读取内容

2024-05-26

允许任何人读取属性名称,但阻止未经授权的人读取值的内容的正确数据库规则是什么。这是一个订单系统,我在设置属性值之前检查是否存在相同的 ID。或者还有其他方法可以做到这一点吗?谢谢。

这是我到目前为止所想到的。

{
  "rules": {
    "orders": {
      ".read": true,
      ".write": true,

    }
  }
}

在 Firebase 数据库安全模型中,您要么有权访问整个节点,要么无权访问它。您无法授予用户对集合中每个节点的子集的访问权限。看文档中的规则级联 https://firebase.google.com/docs/database/security/securing-data#read_and_write_rules_cascade.

通常,您会将集合分为两部分:一份包含公共部分,另一份包含私有部分。

{
  "rules": {
    "ordernames": {
      ".read": true,
    },
    "orders": {
      ".read": "auth !== null",
    }
  }
}

另请参阅:

  • 如何使用 Firebase 安全规则创建公共/私人用户配置文件? https://stackoverflow.com/questions/38921824/how-to-create-public-private-user-profile-with-firebase-security-rules
  • Firebase:如何构建公共/私人用户数据 https://stackoverflow.com/questions/38648669/firebase-how-to-structure-public-private-user-data
  • Firebase 安全规则:公共数据与私有数据 https://stackoverflow.com/questions/19891762/firebase-security-rules-public-vs-private-data
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Firebase:允许读取属性名称,但不允许读取内容 的相关文章

随机推荐