问题描述 投票:0回答:0
I在“身份验证”中检查了这实际上是我的ID。 我已经设定了我的规则:

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”。我在做什么错? enter image description here 您的查询要求“事件”集合中的所有文档,但是您的规则要求客户只能请求文档“成员”数组字段包含特定字符串。 因此,该规则是拒绝查询,因为它要求规则不允许的数据。

Firestore安全规则不是过滤的(您应该阅读并理解此文档)。 您在客户端上的查询应包含一个过滤器,该过滤器仅请求规则允许的文档,这意味着您应该在“成员”字段上有一个“ array-contains”filter

firebase google-cloud-firestore firebase-security
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.