google-cloud-firestore - 如何允许身份验证部分下具有特定用户 UID 的用户写入 Firestore 并让其他用户读取特定文档的数据?
问题描述
我试图在身份验证部分只允许一个具有特定 UID 的用户写入文档并休息以从中读取。
我还没有尝试过,因为我无法理解它背后的概念。
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
我希望输出是完整的 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'
}
}
}
推荐阅读
- python - python文件在没有库的情况下进行ast和back
- javascript - 正则表达式仅修剪逗号,但不在文本之间和引用时修剪 - Java 脚本
- scala - 如何使此定期指标收集代码更具功能性(不可变状态)?
- excel - VBA Excel - 在 Outlook 邮件正文中粘贴图表(不是图像)
- java - 无法写入具有权限的 SD 卡
- java - Spring Data Rest:摘录为封闭投影
- html - 如何让我的 CSS Grid 布局响应式?
- c# - 在模拟另一个用户时请求 Kerberos 票证时,安全包中没有凭据
- r - ifelse 测试选择一个值而不是两个
- jquery - 在数据库中插入选中的复选框值并在未选中时将其删除