javascript - 更新 Firestore 上的规则后,我无法读取数据(React Native)
问题描述
我设置的规则是允许读取: if resource.data.uid == request.auth.uid;
我怎么称呼它是这样的
return async (dispatch) => {
await firebase
.firestore()
.collection("patients")
.doc(firebase.auth().currentUser.uid)
.collection("patient")
.orderBy("creation", "desc")
.get()
.then((result) => {
let Patients = result.docs.map((doc) => {
const data = doc.data();
const id = doc.id;
return { id, ...data };
});
dispatch({ type: GET_PATIENTS, Patients });
});
};
我该如何解决?
firebase 规则
match /databases/{database}/documents {
match /patients/{patientsID}{
match /patient/{patientID}{
allow read: if resource.data.uid == request.auth.uid;
allow create: if request.resource.data.uid == request.auth.uid;
allow update: if request.resource.data.uid == request.auth.uid;
allow delete: if resource.data.uid == request.auth.uid;
match /diagnostic/{diagnosticID}{
allow read: if true;
allow write: if request.resource.data.uid == request.auth.uid;
}
}
}
}
}
数据图像
解决方案
规则不会自行过滤数据。相反,他们只是确保所请求的数据符合您的规则。
因此,您的查询需要匹配规则,这意味着它们还需要按 UID 过滤:
.collection("patient")
.orderBy("creation", "desc")
.where("uid", "==", firebase.auth().currentUser.uid)
推荐阅读
- angular - Cant Fix Error NgFor 仅支持绑定到 Iterables,例如 Arrays Angular9
- django - Django URL 顺序
- c# - Marshal.Sizeof() 返回意外值
- r - 带有 COMCreate("Outlook.Application") 的 RDCOMClient 使 R 崩溃
- artifactory - 将 Artifactory pro 从 6.10.9 更新到 7.6.3
- sql - PySpark 或 SQL:消耗合并
- javascript - 带有 vee-validate ValidationObserver 组件的 Vue 自定义元素错误
- java - 加载所有实体作为聚合根的一部分
- javascript - React 中的 ...{} 是什么(三个点后跟大括号)
- mysql - 如何从旧的 XAMPP 数据备份中正确恢复数据