【发布时间】:2018-05-31 16:47:23
【问题描述】:
我有一个包含两个集合的 Firestore 数据库:用户和锦标赛。用户具有“参与者”角色和“管理员”角色,并由用户文档中的“isParticipant”和“isAdmin”布尔值表示:
/users/{userId}:
isParticipant: true
isAdmin: true
我为这些集合设置了访问规则,如下所示:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow create, read;
allow update: if request.auth.uid == userId;
}
match /tournaments/{tournamentId} {
allow create, read, update: if request.auth.uid != null;
}
}
}
但是,我真正想做的是将锦标赛的创建限制为“管理员”角色的用户。我已经在代码中执行此操作,但希望增加 db 规则的安全性,以防止除管理员用户之外的任何人创建锦标赛。
有没有办法在规则语法中引用不同集合的数据元素?比如:
match /tournaments/{tournamentId} {
allow create: if resources.users.userId.isAdmin == true;
}
?
提前致谢。
【问题讨论】:
标签: google-cloud-firestore firebase-security