【发布时间】:2018-04-23 12:34:48
【问题描述】:
我存储在数据库中的模型是这样的:
{
"ownerUid": <my auth UID>,
"teamName: "Team 1",
"teamDescription: "Team 1 desc"
}
而我的初始访问规则是这样的:
service cloud.firestore {
match /databases/{database}/documents {
match /teams/{teamId} {
allow read: if resource.data.ownerUid == request.auth.uid;
allow write: if true; //ignore this
}
}
}
我为获取团队而运行的查询如下:
Query query = FirebaseFirestore.getInstance()
.collection("teams")
.orderBy("teamName")
运行这个查询总是会导致“PERMISSION DENIED”,我很不确定这是什么原因。
出于测试目的,我也尝试了以下规则:
allow read: if true; //Works
allow read: if request.auth.uid != null; //Works
allow read: if request.auth.uid == <my auth uid>; //Works
allow read: if resource.data.ownerUid != null; //Fails
在成功的规则上,我可以看到返回的团队中的ownerUid,并且看到它不为null,并且与匹配。
【问题讨论】:
-
所以您希望用户只能阅读他们拥有的团队?
标签: android firebase google-cloud-firestore firebase-security