google-cloud-firestore - 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: Property email is undefined on object。
测试如下:
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 和用于身份验证的电子邮件的示例有点令人困惑,因此值得警告。
解决方案
推荐阅读
- android - Flutter Android 应用程序未遵守并给出如下错误
- powershell - Powershell Invoke-WebRequest SSL/TLS
- java - 尝试从 Edmtdev 克隆 Android Uber 应用程序,java.lang.RuntimeException: Unable to start activity ComponentInfo,android.view.InflateException
- c# - 同一应用程序的多个实例引发 StackOverflow 异常
- ionic-framework - 在 Ionic4 中,离子数据存储在手机中不起作用
- quarkus - 如何正确使用 quarkus 和 smallrye 做事件驱动的微服务
- python - SNMP MIB 子树注册和注销
- python - 使用python从k-means完成的每个集群中查找前10个中心值最多
- amazon-web-services - 如何使用 boto3 创建特定类型的 IAM 角色?
- lua - 文件写入中的错误“尝试索引布尔值”