Google cloud firestore Firestore emulator和request.auth.email生成一个';对象';上未定义属性电子邮件;错误

Google cloud firestore Firestore emulator和request.auth.email生成一个';对象';上未定义属性电子邮件;错误,google-cloud-firestore,firebase-authentication,firebase-security,firebase-cli,Google Cloud Firestore,Firebase Authentication,Firebase Security,Firebase Cli,多亏了大量的资源,我安装了firestore emulator和我的测试环境,除了测试以下规则外,一切都很顺利: rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { function invitationIsForMe(destEmail) { return request.auth.email == destEmail; }

多亏了大量的资源,我安装了firestore emulator和我的测试环境,除了测试以下规则外,一切都很顺利:

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和电子邮件进行身份验证的示例有点混乱,因此值得一提。

您的代码似乎没有建立经过身份验证的用户的电子邮件地址。它只需要一个,然后失败了,因为它不是为模拟用户实际设置的。请记住,参数需要在
initializeTestApp
函数上命名。您是否尝试过这样命名:
return firebase.initializeTestApp({projectId:YORGA_PROJECT_ID,auth:auth}).firestore()initializeTestApp
函数上命名。您是否尝试过这样命名:
return firebase.initializeTestApp({projectId:YORGA_PROJECT_ID,auth:auth}).firestore()