firebase - 带有数组/列表属性的 Firebase 安全规则语法
问题描述
在具有路径“组织”的 Firebase Firestore 集合中,每个文档都包含可以更新或删除该文档的用户的字符串 userID 列表。
export interface Organization{
name?: string,
owners: string[]
}
我想创建一个 Firebase 安全规则,以确保只有具有此列表中 uid 的登录用户才能编辑或删除该对象。不确定适当的语法。
service cloud.firestore {
match /databases/{database}/documents {
match /organizations/{organization} {
allow read: if true;
allow create: if request.auth != null;
/// What should be the syntax here?
allow update, delete: if request.auth != null && (request.auth.uid in resource.data.owners); // <--------- What should be the syntax for this line?
}
解决方案
好的,在这里回答我自己的问题,以防它对其他人有用。
看起来上面的“in”语法实际上有效——尽管这是一个完整的猜测,我无法在 firebase 安全角色文档中找到任何文档。
最终代码:
service cloud.firestore {
match /databases/{database}/documents {
match /organizations/{organization} {
allow read: if true;
allow create: if request.auth != null;
allow update, delete: if (request.auth != null) && (request.auth.uid in resource.data.owners);
}
推荐阅读
- servicenow - 现在如何使用 OAuth 对我们的服务客户端进行身份验证?
- python - pip:创建进程失败。我该如何解决?
- linux - 根据指令文件重命名目录中的文件
- linux - Spansion s25hx512 闪存驱动程序
- r - 在 R 中使用 Sys.setenv()
- reactjs - Can't access Content-Disposition in axios
- angular11 - 我如何以角度为以下方法编写单元测试用例
- android - 如何获取android消息应用程序的包名?
- php - Laravel 8 storage/framework/cache/data/ee 文件夹将用户设置为 root:root 而不是 apache:apache 权限被拒绝
- web-applications - 具有大量页面的现代 Web 应用程序的架构