【发布时间】:2022-08-06 23:17:26
【问题描述】:
我在 Google Firebase 上有一个 Firestore 数据库,里面有“村庄”集合。 我想限制特定用户的每个文档的读/写功能,并将他们的 uuid 作为文档键。
我已将规则添加到 Firestore 中的“规则”选项卡,但是当我尝试获取数据时,我收到一条错误消息,提示我没有对 Firestore 的权限...
这是我的规则:
rules_version = \'2\';
service cloud.firestore {
match /databases/{database}/documents {
match /village/{villageId} {
allow read, write: if request.auth != null && request.auth.uid == villageId;
}
}
}
如果我从 Firestore 中删除我的规则,这是成功返回数据的代码 sn-p:
useEffect(() => {
const collectionRef = collection(db, \"village\");
const q = query(collectionRef, orderBy(\"timestamp\", \"desc\"));
const unsubscribe = onSnapshot(q, (querySnapshot: any) => {
setVillage(
querySnapshot.docs.map((doc) => ({
...doc.data(),
id: doc.id,
timestamp: doc.data().timestamp?.toDate().getTime(),
}))
);
});
return unsubscribe;
}, []);
标签: reactjs google-cloud-firestore firebase-security