【发布时间】:2022-01-01 05:53:22
【问题描述】:
在 Firebase Firestore 中: 我有三个不同的集合,1:-“用户”,2:-“ContactUs”,第三个“报告”。 在用户中,文档是由 uid 创建的,然后它内部有一个名为“uid”的字段。 在 ContactUs 和 Reports 中,文档是随机生成的,并且每次都不同。
我已经尝试了以下规则,但我不确定,请帮助我更正它。在 ContactUs 和 Reports 中,是否应该有 {userId} 或其他内容,因为它每次都不同,我将如何将其与 uid 进行比较,因为其中没有 uid 字段?
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow write, update, delete: if
request.auth.uid == userId;
allow read: if request.auth.uid != null;
}
match /ContactUs/{userId} {
allow write, update, delete: if
request.auth.uid == userId;
allow read: if request.auth.uid != null;
}
match /Reports/{userId} {
allow write, update, delete: if
request.auth.uid == userId;
allow read: if request.auth.uid != null;
}
}
}
在实时数据库中:我附上了一张照片供参考,它显示了用户开始新聊天时创建的孩子的详细信息。
我已经实时尝试了以下规则,但它显示:- 您的安全规则不安全。任何经过身份验证的用户都可以窃取、修改或删除您数据库中的数据。
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
请帮助我正确设置它们。谢谢。
【问题讨论】:
标签: firebase firebase-realtime-database google-cloud-firestore firebase-security