Firebase 规则 - 如果用户的 uid 等于文档的字段值 userId 则允许读取
我试图仅在用户的 uid 与 userId 匹配(用红色圈出)时才允许读取硬币的文档。
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
match /coins/{coinId} {
allow read: if request.auth != null && resource.data.userId == request.auth.uid;
allow write: if request.auth != null;
}
}
}
当我登录我的帐户时,此规则在控制台中返回错误。并且没有数据显示。 快照侦听器中未捕获的错误:FirebaseError:缺少权限或权限不足。
根据我在此处阅读的所有内容,以下代码似乎应该有效,但事实并非如此。
I am trying to only allow reads coins's documents if the user's uid matches the userId (encircled in red).
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
match /coins/{coinId} {
allow read: if request.auth != null && resource.data.userId == request.auth.uid;
allow write: if request.auth != null;
}
}
}
This rule returns an error in the console when I log into my account. And no data is displayed.Uncaught error in snapshot listener: FirebaseError: Missing or insufficient permissions.
Based on everything I've read here it seems like the following code should work, but it doesn't.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有同样的问题。
改变:
资源.data.userId == request.auth.uid;
到:
request.resource.data.userId == request.auth.uid;
Had the same problem.
Changed:
resource.data.userId == request.auth.uid;
To:
request.resource.data.userId == request.auth.uid;