【发布时间】:2018-08-24 15:54:34
【问题描述】:
我有一个这样的火库:
:stores
|
$Store
:orders
|
$Order
:items
我想使用具有 workerUid 与 request.auth.uid 相同但出现 错误:缺失或不足的用户从我的数据库中读取订单权限。
我的 Firebase 规则的重要部分:
service cloud.firestore {
match /databases/{database}/documents {
//Matches any document in the stores collection
match /stores/{store} {
function isStoreAdmin(uid) {
return get(/databases/stores/$(store)).data.adminUid == uid;
}
function isStoreWorker(uid) {
return get(/databases/stores/$(store)).data.workerUid == uid;
}
allow read: if request.auth.uid != null;
allow write: if request.auth.uid == resource.data.adminUid;
//Matches any document in the orders collection
match /orders/{document=**} {
allow read, write: if isStoreAdmin(request.auth.uid) || isStoreWorker(request.auth.uid);
}
}
}
}
有趣的是,如果我这样做,它会起作用:
match /orders/{document=**} {
allow read, write: if isStoreWorker(request.auth.uid);
}
或者这个:
match /orders/{document=**} {
allow read, write: if request.aut.uid != null;
}
部署规则时,我没有收到任何语法错误,所以我真的不明白为什么这不起作用。有没有人有任何想法?非常感谢!
编辑:
function readAllDocuments(collectionReference, callback,finishedCallback){
collectionReference.get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
callback(doc.id,doc.data());
});
finishedCallback();
});
}
const storeDocument = getRootCollection(STORES_COLLECTION_ID).doc(storeId);
const orderCollection = storeDocument.collection(STOREORDERS_COLLECTION_ID);
orders=new Map();
readAllDocuments(orderCollection, function (id, data) {
orders.set(id,data);
},function(){
finishedLoading();
});
【问题讨论】:
-
请编辑您的问题以包含触发错误的代码。
-
@FrankvanPuffelen:请看我的编辑。但我很确定错误一定在规则的某个地方。
标签: firebase google-cloud-firestore firebase-security