firebase - Firebase 安全规则在 get() 或 exists() 操作 PERMISSION_DENIED 时始终为假
问题描述
我完成了我的应用程序,我正在实施安全规则。我目前正在尝试验证银行中是否存在用户,如果存在,他将能够读取和写入特定路径。我正在使用 Firestore:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents{
match /Usuarios/{documentID} {
allow read, update, delete: if request.auth.uid != null && request.auth.uid == documentID;
allow create: if request.auth.uid != null;
match /Manejo/{manejoID} {
allow write, read: if exists(/databases/$(database)/documents/$(request.auth.uid)); // The id is never exist... even when it does exist in my database, this operation simply DOES NOT WORK despite the document with the Uid existing in the database
}
}
}
编辑1:
match /Manejo/{manejoID} {
allow write, read: if true;
}
这个条件也行不通……
解决方案
您需要声明要在哪个集合中检查文档是否存在docId == userId
和
allow write, read: if exists(/databases/$(database)/documents/$(request.auth.uid));
你不声明集合。
查看文档中的以下示例,该示例检查集合docId == userId
中users
是否存在该文档。看看/users/
后面是如何添加的$(database)/documents
。
allow create: if request.auth != null && exists(/databases/$(database)/documents/users/$(request.auth.uid))
我知道想要检查Usuarios
集合中文档的存在。如果这个假设是正确的,请执行以下操作:
allow write, read: if exists(/databases/$(database)/documents/Usuarios/$(request.auth.uid));
请注意,您可能会对这篇 Firebase 博客文章感兴趣。
推荐阅读
- python - 具有多列的数据框的不同聚合
- java - 如何在使用 camera2 api 录制时向视频添加自定义过滤器
- email - 电子邮件模板 | 在主题上方插入自定义 HTML 块
- vue.js - 在构建部署到 S3 后获取环境变量是 Vuejs
- android - 使用改造时如何更新 RecyclerView?
- powerbi - PowerBI DAX Measure 不拾取行
- c - 如何在C中打印指向哪个指针成员的值
- php - Symfony 4.26 / php 7.4.9 - 找不到驱动程序
- sql - 如何在不使用窗口函数 Oracle 的情况下获取每组的第一行?
- testing - 什么是好的进程 I/O 速率?