Database 我在firestore安全规则中遗漏了什么,它拒绝所有读写操作?

Database 我在firestore安全规则中遗漏了什么,它拒绝所有读写操作?,database,firebase,google-cloud-firestore,nosql,Database,Firebase,Google Cloud Firestore,Nosql,我正在使用firebase规则模拟器,但它拒绝为经过身份验证或未经身份验证的用户进行读、写操作 rules_version = '2'; service cloud.firestore { match /databases/collection1/{document=**} { allow read: if true; allow write: if request.auth.uid != null; } match /databases/collection2/

我正在使用firebase规则模拟器,但它拒绝为经过身份验证或未经身份验证的用户进行读、写操作

rules_version = '2';
service cloud.firestore {
    match /databases/collection1/{document=**} {
    allow read: if true;
    allow write: if request.auth.uid != null;
  }
  match /databases/collection2/{document=**} {
    allow read: if false;
    allow create: if request.auth.uid != null;
    allow update, delete: if false;
  }
}

你的规则应该是这样开始的:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
您的规则缺少
/databases/{database}
部分,因此它们与任何内容都不匹配并拒绝所有内容。您可以这样重新编写示例:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // Matches every document in collection1 and every subcollection under it
    match /collection1/{document=**} {
       allow read;
       allow write: if request.auth.uid != null;
    }
   // Matches every document in collection2 and every subcollection under it
    match /collection2/{document=**} {
       allow create: if request.auth.uid != null;
    }
  }
}
这允许以下模拟请求:

  • 获取未经验证的/collection1/doc1
  • create authenticated/collection1/doc2
  • create authenticated/collection2/doc3

其他模拟请求按预期被拒绝


希望有帮助

模拟读/写拒绝,即使在我用您编写的安全规则替换我的安全规则之后,它也会拒绝每次读/写。在嵌套的匹配语句中,如果我删除“/collection1”,它会按需要工作。但我希望能够为单个集合设置自定义规则。idk,出了什么问题。更新了规则以简化并添加了一些示例模拟请求。您应该能够像这样为单个集合设置规则。你能给你的问题添加一些例子吗?非常感谢你,胡安!我真的很努力,再一次谢谢。