【问题标题】:Allow Read access to one specific collection in Firebase Firestore允许对 Firebase Firestore 中的一个特定集合具有读取权限
【发布时间】:2020-07-17 00:44:57
【问题描述】:

在我的 android 应用上,我使用 Firebase Firestore 存储“用户名”集合,以便在用户登录之前查询以检查所选用户名是否可用。

目前我的项目有 2 个主要集合:“用户”和“用户名”。我试图仅在“用户名”集合中允许读取访问权限。我的程序失败了,因为当我尝试在用户通过身份验证之前查询“用户名”集合时,它说我没有正确的权限。

我的规则非常基本,但我想知道是否可以以某种方式修改它们以使我的项目正常工作。规则如下:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}

firestore 数据库是什么样子的视觉概念:

【问题讨论】:

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


    【解决方案1】:

    如果您想以不同于其他所有内容的方式处理“用户名”集合,请按名称调用它,并将完全读取权限分配给每个人:

        match /usernames/{id} {
          allow read: if true;
        }
    

    我建议花一些时间研究documentation on security rules,以更好地了解它们的工作原理,并学习如何自己制定规则。

    【讨论】:

    • 成功了,非常感谢您花时间回答我的问题
    • 在 Stack Overflow 上,习惯上单击复选框将答案标记为正确。
    猜你喜欢
    • 2017-01-13
    • 2021-06-24
    • 1970-01-01
    • 2023-02-07
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多