gpt4 book ai didi

javascript - Firestore : cannot securely query data with a WHERE clause that uses both currentUser. uid 和 FieldPath.documentId()

转载 作者:行者123 更新时间:2023-12-04 15:08:53 27 4
gpt4 key购买 nike

firestore.rules

match /databases/{database} {
match /documents/board/{boardId}/{document=**} {
allow read: if (resource.data.creatorId == request.auth.uid);

查询 1(有效)

this.db
.collection("board")
.where("creatorId", "==", app.auth().currentUser.uid).onSnapshot(...)

查询 2(不起作用,返回 FirebaseError:权限缺失或不足)

this.db
.collection("board")
.where("creatorId", "==", app.auth().currentUser.uid)
.where(app.firestore.FieldPath.documentId(), "in", boardIds).onSnapshot(...)

这对我来说没有任何意义。查询 2 是查询 1 的子集,但与查询 1 不同,它违反了安全规则。

有人知道为什么吗?

最佳答案

如果文档的 creatorId 不是进行查询的用户,您的安全规则将阻止读取文档。

查询 1 有效,因为过滤器遵循规则并且不会读取创建者不是当前用户的文档。

然后,查询 2 有第二个子句,这意味着:“我想要 DocID 是 boardIds 数组之一的文档”。

问题可能是 documentID 被认为是文档的一个字段。

如果单独应用第二个子句,它可能会崩溃,因为 userA 可能会尝试访问 userB 文档以检查 docID 是否在数组中,这是不允许的。

因此,即使第二个查询的RESULT 是查询 1 的子集,但这并不意味着(或似乎意味着)QUERY 本身是允许的。

关于javascript - Firestore : cannot securely query data with a WHERE clause that uses both currentUser. uid 和 FieldPath.documentId(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65572231/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com