gpt4 book ai didi

firebase - 使用访问规则中的字段写入 Firestore 时权限缺失或不足

转载 作者:行者123 更新时间:2023-12-03 10:01:12 24 4
gpt4 key购买 nike

尝试写入 Firestore 时出现错误。

我正在尝试将包含用户 uid 的字段用于我的安全规则。

service cloud.firestore {
match /databases/{database}/documents {

match /messages/{document=**} {
allow read: if resource.data.user_uid == request.auth.uid;
allow write: if resource.data.user_uid == request.auth.uid;
}
}
}

如果我的 Firestore 数据库中有数据,则读取规则工作正常 - 但是当我尝试写入时,我得到: Error: Missing or insufficient permissions.这个写入规则有什么问题吗?

附言如果我将规则更改为此,我可以写入我的数据库 - 但这对于我的目的来说不够安全:
 match /messages/{document=**} {
allow read: if resource.data.user_uid == request.auth.uid;
allow write: if request.auth != null;
}

最佳答案

resource.data指已存储的数据,因此您的规则允许用户仅更新已包含其用户 ID 的数据。

您可能要检查的是 request.resource.data这是传入的新数据。

这里有一份关于这些字段和其他安全规则的相当广泛的文档:https://firebase.google.com/docs/firestore/security/rules-conditions

关于firebase - 使用访问规则中的字段写入 Firestore 时权限缺失或不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46635830/

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