Firestore模拟器和request.auth.email生成“对象上未定义属性电子邮件”错误

问题描述

多亏了https://www.youtube.com/watch?v=VDulvfBpzZE的资源,我安装了Firestore模拟器和测试环境,除了我要测试以下规则时,一切都很好:

rules_version = '2';
service cloud.firestore {
    match /databases/{database}/documents {

    function invitationIsForMe(destemail) {
        return request.auth.email == destemail; 
    }

    match /invitations/{inviteId} {
        allow read,delete: if invitationIsForMe(resource.destemail);
    }
}

这会在测试中产生错误 FirebaseError: 在对象上未定义属性电子邮件

测试如下:

const me = {uid: 'myuserid',email: 'me@foo.bar'};

const getDb = (auth) => {
    return firebase.initializeTestApp({projectId: YORGA_PROJECT_ID,auth}).firestore();
}

describe('firestore structure and rules',() => {
    it("Can read an invitation sent to me",async () => {
        const db = getDb(me);
        const testDoc = db.collection('invitations').where('destemail','==',me.email);
        await firebase.assertSucceeds(testDoc.get());
    })
}

如果我使用request.auth.uid对其进行测试,则可以正常工作(但这不是我要寻找的逻辑)。 所以我的问题是:这是Firestore模拟器的限制吗?我希望不是,而只是我,但是如果是这种情况,我认为在初始化测试基础时给出的带有uid和auth电子邮件的示例有点令人困惑,因此值得警告。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...