【问题标题】:Firebase Security Rules to allow read允许读取的 Firebase 安全规则
【发布时间】:2020-07-11 11:37:30
【问题描述】:

我正在学习 Firebase 数据库并尝试设置安全规则。首先,我正在创建非常宽松的规则,如下所示:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/users/{user_id} {
    allow read, write: if true;
  }
}

我在 Firebase 控制台中找到了 Rules Playground 工具并尝试 get 一个文档:

但是当我点击运行时,我得到“模拟读取被拒绝”。

我错过了什么?为什么我的规则不允许读取?我需要更改哪些内容才能允许读写?

【问题讨论】:

    标签: firebase google-cloud-firestore firebase-security


    【解决方案1】:

    您的规则不正确。看起来您将路径编辑得太远了。您的外部匹配应始终为“/databases/{database}/documents”。如果你想允许完全访问用户集合,整个事情应该是这样的:

    rules_version = '2';
    service cloud.firestore {
      match /databases/{database}/documents {
        match /users/{user_id} {
          allow read, write: if true;
        }
      }
    }
    

    【讨论】:

    • 谢谢。这样可行。我很困惑firebase.google.com/docs/rules/rules-language 的大多数示例当时如何工作。其中许多没有嵌套 match 块。
    • 不要查看服务“firebase.storage”的那些。仅使用“cloud.firestore”。
    • 啊...我什至没有注意到差异。
    猜你喜欢
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    • 2021-07-14
    • 2021-09-08
    • 2016-02-26
    相关资源
    最近更新 更多