【发布时间】:2021-12-30 06:15:14
【问题描述】:
使用本地模拟器,我正在尝试为我的删除和更新测试一条规则,如下所示:
match /posts/{postId} {
allow read: if true;
allow create: if true;
allow delete, update: if (resource.data.user.uid == request.auth.uid)
}
在我的测试文件中,我写了我正在尝试执行的现有文档的确切位置的路径,例如删除:
it("If creator, Allow delete/update items in the post/comment collection", async () => {
const db = firebase
.initializeTestApp({ projectId: MY_PROJECT_ID, auth: myAuth })
.firestore();
const testDoc = db
.collection("general")
.doc("spaces")
.collection("spaces")
.doc("9LbUetZxWeL1ln5hv9ug")
.collection("posts")
.doc("RtUnezdAgXUfWmRSPpkF");
await firebase.assertSucceeds(testDoc.delete());
});
但是当我运行这个测试时,它给了我这个错误。但是,我知道这个文档存在,我希望在我的资源中获取的 user.uid 也是如此。我尝试使用此模拟器的方式有问题吗?
我还看到,如果我进入我的本地模拟器 firestore 数据库,我可以对文件进行硬编码,特别是调用 route my test 到它,然后它就可以工作了。
【问题讨论】:
-
检查您是否连接到正确的项目。您说数据存在并且具有
user.uid属性,但来自数据库的响应说没有属性user。
标签: javascript firebase react-native firebase-security