我目前正在第一次使用Firestore并试图了解安全规则。我现在的问题很简单,我可以通过做一些研究找出答案,但我想确定我做的是正确的,所以我觉得最好在这里问一下。
如果我在Firestore中有两个集合,一个名为“A”,另一个“B”,如果我希望经过身份验证的用户在A中读取,写入,更新,删除...以及每个人都要读取,那么我的安全规则必须是什么? B但只是经过身份验证的用户在B中编写,更新,删除...
编辑:以下是他们将B规则应用于所有集合的当前规则:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if true;
allow write: if request.auth.uid != null;
}
}
}
如果你看看documentation on authentication in security rules,你会发现这些规则:
service cloud.firestore { match /databases/{database}/documents { // Allow the user to access documents in the "cities" collection // only if they are authenticated. match /cities/{city} { allow read, write: if request.auth.uid != null; } } }
为您的用例修改,这类似于:
service cloud.firestore {
match /databases/{database}/documents {
match /A/{id} {
allow read, write: if request.auth.uid != null;
}
match /B/{id} {
allow read;
allow write: if request.auth.uid != null;
}
}
}