我尝试访问某些文档时遇到问题。它说我没有获得访问docuemnt的许可。所以我在Firestore规则中有以下内容
match /reservations/reservations-request/list/{reservationInfo} {
allow read: if get(/databases/$(database)/documents/reservations/reservations-request/list/$(reservationInfo)/members-id/data).data.driverId == request.auth.uid ||
get(/databases/$(database)/documents/reservations/reservations-request/list/$(reservationInfo)/members-id/data).driverId == request.auth.uid;
allow write: if false;
}
在模拟器中,当我使用与我在我的应用程序中使用的相同的uid和电话号码时,它表示我可以获得具有此路径的文档。但是,当我尝试在应用程序中执行相同的操作(使用相同的用户uid和电话号码)时,它不允许我访问文档。我尝试访问文档的代码是这样的:
fetchReservationsAsDriver(type: string, driverId: string): Promise < any > {
var size = 0;
var reservations: ReservationDB[] = [];
return new Promise((resolve, reject) => {
let reservation_aux;
firebase.firestore().collection('reservations').doc("reservations-requested").collection('list').where("driver.id", "==", driverId).get().then(function (array) {
size = array.size;
if (size == 0) {
resolve(reservations);
}
array.forEach(function (doc) {
reservation_aux = doc.data();
reservations.push(reservation_aux);
console.log(doc.id, " => ", doc.data());
});
resolve(reservations);
})
.catch(function (error) {
console.log("Error getting documents: ", error);
reject(error);
});
});
}
感谢您的帮助!
---------编辑----------
我弄清楚究竟是什么问题:
如果我有这个:
match /reservations/requested-reservations/list/{reservationInfo} {
allow read: if get(/databases/$(database)/documents/reservations/requested-reservations/list/$(reservationInfo)/members-id/data).data.driverId == request.auth.uid
}
firestore规则不允许我从集合&#34; list&#34;中获取任何文档,但是,我发现如果更改了该规则:
match /reservations/requested-reservations/list/{reservationInfo} {
allow read: if get(/databases/$(database)/documents/reservations/requested-reservations/list/IYB0710-2018-06-13-1528922084314/members-id/data).data.driverId == request.auth.uid
}
firebase允许我阅读文档(至少是名为&#34; IYB0710-2018-06-13-1528922084314&#34;的文档,这是&#34; list&#34;集合中的文档之一)。
这意味着当我尝试从我的应用程序中使用此命令获取一组文档时,他实际上没有用文档名替换$(reservationInfo):
firebase.firestore().collection('reservations').doc(type).collection('list').where("driver.id", "==", driverId).get().then(function (array) {
// Do Something
})