首页 > 解决方案 > 如何允许身份验证部分下具有特定用户 UID 的用户写入 Firestore 并让其他用户读取特定文档的数据?

问题描述

我试图在身份验证部分只允许一个具有特定 UID 的用户写入文档并休息以从中读取。

我还没有尝试过,因为我无法理解它背后的概念。

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

我希望输出是完整的 Firestore 规则,我可以直接使用也非常感谢对概念的解释。

标签: google-cloud-firestore

解决方案


service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read : if request.auth.uid != null;
      allow write,delete : if request.aurh.uid = userId //you'll have to fetch userId from document. You can store userId in a field like 'createdBy'
    }
  }
}

推荐阅读