rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /incidents/{document=**} {
allow read, write: if
request.auth.uid in resource.data.members
}
}
}
import { collection } from 'firebase/firestore';
const incidentsCollection = collection(db, 'incidents');
onSnapshot(incidentsCollection, (querySnapshot) => {
const fetchedIncidents = [];
querySnapshot.forEach((doc) => {
fetchedIncidents.push({
id: doc.id,
...doc.data(),
});
});
在上述所有内容中,我都会获得“允许_DENIED”。我在做什么错?
您的查询要求“事件”集合中的所有文档,但是您的规则要求客户只能请求文档“成员”数组字段包含特定字符串。 因此,该规则是拒绝查询,因为它要求规则不允许的数据。
Firestore安全规则不是过滤的(您应该阅读并理解此文档)。 您在客户端上的查询应包含一个过滤器,该过滤器仅请求规则允许的文档,这意味着您应该在“成员”字段上有一个“ array-contains”filter
。