google-cloud-functions - 读取、更新和删除的 Firestore 规则
问题描述
我是一名非开发人员,正在寻找有关 Firestore 项目安全规则的指导。
Firestore 数据库截图:
Swaps集合中的每个文档应该只能由两个用户访问,一个提供者和一个接收者。
要允许在Swaps集合中创建新文档,用户需要将自己指定为接收者,这意味着经过身份验证的用户 ID 必须与请求的ReceiverID匹配。
但是,发送者和接收者都应该被允许更新、阅读和删除文档。为此,我想将接收者与交换文档的ReceiverID匹配,将给予者与交换文档的GiverID 匹配
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /Swaps/{document=**} {
allow read: if request.auth.uid == resource.data.GiverID;
allow update: if request.auth.uid == resource.data.GiverID;
allow delete: if request.auth.uid ==resource.data.GiverID;
allow read: if request.auth.uid == resource.data.ReceiverID;
allow update: if request.auth.uid == resource.data.ReceiverID;
allow delete: if request.auth.uid == resource.data.ReceiverID;
allow create: if request.auth.uid == request.resource.data.ReceiverID;
}
目前,唯一有效的接缝规则是创建。读取、更新和删除对提供者或接收者都不起作用。
解决方案
试试这样:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /Swaps/{Swap} {
allow read: if request.auth.uid == resource.data.GiverID || request.auth.uid == resource.data.ReceiverID;
allow update: if request.auth.uid == resource.data.GiverID || request.auth.uid == resource.data.ReceiverID;
allow delete: if request.auth.uid == resource.data.GiverID || request.auth.uid == resource.data.ReceiverID;
allow create: if request.auth.uid == request.resource.data.ReceiverID;
}
推荐阅读
- ruby - 如何向我的“发布”请求添加更多信息(Sinatra)
- javascript - 无法解决承诺
- mysql - Mysql For Excel:没有连接显示
- python - Django 在网格行中显示有限的图像
- c# - 使用 Angular 时,无法使用默认路径加载 aspnet.core 服务器路由
- windows - 重定向两个命令的输出
- reactjs - 将 props 传递给 React Router 的 Link 组件
- r - GA 包中未使用的参数
- python - Tensorflow 错误“无法为张量“输入:0”提供形状 (4, 1) 的值,其形状为“(?, 2)”
- android - 多个dex文件定义Lcom/google/android/gms/auth/api/signin/zzc;