我正在使用Firebase Cloud Firestore,我想修改我的规则以限制用户查询集合。
不应该允许这样做:
firestore().collection("users").get()
但是应该允许这样做:
firestore().collection("users").doc("someUserId").get()
目前,我的规则如下:
match /users/{userId} {
allow read;
}
但此规则允许查询“用户”集合。
如何才能允许单个文档获取,而不是收集查询?
答案 0 :(得分:6)
您可以将阅读规则分为获取和列表。获取的规则适用于单个文档的请求,列表规则适用于查询和集合请求(docs)。
match /users/{userId} {
//signed in users can get individual documents
allow get: if request.auth.uid != null;
//no one can query the collection
allow list: if false;
}
答案 1 :(得分:0)
尝试以下内容。我还没有能够测试它,所以如果我错误地输入了某些内容,我会道歉。
match /users/{userId} {
allow read: if $(request.auth.uid) == $(userId);
}