我有一个像这样的消防局
我有这样的消防安全规则。
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if request.auth != null;
}
match /users/{userId}/{document=**} {
allow read, create, update, delete: if request.auth != null && request.auth.uid == userId ;
}
}
}我该怎么制定规则-
发布于 2021-04-03 19:27:55
规则中有一个重叠匹配语句,因为您使用match /{document=**}映射到数据库中的所有文档(参见文档)。
因此,既然:
match /{document=**}语句,您的规则是allow read: if request.auth != null;。每个经过身份验证的用户都可以读取任何user文档(您不像对users集合那样限制users文档。实际上,您不能这样做,因为match /{document=**}没有专门针对users集合)。
最好是移除这个块,只保留下面的块。
match /users/{userId}/{document=**} {
allow read, create, update, delete: if request.auth != null && request.auth.uid == userId ;
}如果需要授予对其他集合的读访问权限,请为每个集合使用规则,而不是使用通配符方法。
PS:您可以反复检查是否真的需要执行match /users/{userId}/{document=**},它授予对users文档的所有子集合的访问权限。您可能只需要做match /users/{userId}。
https://stackoverflow.com/questions/66934680
复制相似问题