【发布时间】:2021-07-03 14:01:37
【问题描述】:
感谢您的帮助。
我有一个文档
/rooms/CAhYMQ3aDFvsDxrIxyg
和规则
rules_version = '2';
service cloud.firestore {
[...]
match /rooms/{roomId} {
allow get;
}
[...]
}
但是当测试这条“路线”时,他们没有通过
(测试实验室)
- 类型模拟:获取
- 本地:/rooms/CAhYMQ3aDFvsDxrIxyga
- 身份验证:真
编辑:
所有规则:
rules_version = '2';
service cloud.firestore {
match /users/{userId}/{anyUserFile=**} {
allow read: if IsAuth();
}
match /users/{userId}/{anyUserFile=**} {
allow write: if IsOwner(userId);
}
match /rooms/{roomId} {
allow get;
}
match /rooms/{roomId}/messages/{messageId}{
allow write: if IsMessageOwner();
}
}
删除的功能只是放东西就可以破坏了。
Edit2:(工作)
rules_version = '2';
service cloud.firestore {
function IsAuth(){
return request.auth != null;
}
function IsOwner(userId){
return IsAuth() && request.auth.uid == userId;
}
function IsMessageOwner(){
return IsAuth() && resource.data.sender_auth.uid == request.auth.uid;
}
match /databases/{database}/documents {
match /rooms/{roomId} {
allow read, get, list: if true;
}
match /users/{userId}/{anyUserFile=**} {
allow read: if IsAuth();
}
match /users/{userId}/{anyUserFile=**} {
allow write: if IsOwner(userId);
}
match /rooms/{roomId}/messages/{messageId}{
allow write: if IsMessageOwner();
}
}
}
我不明白我需要始终声明数据库根目录。 匹配 /rooms/{roomId} 有效:D
【问题讨论】:
-
这似乎对我有用。您能分享一下
[...]的其余规则是什么样的,并分享一个规则游乐场输出的屏幕截图吗? -
信息发送
标签: google-cloud-firestore firebase-security