【发布时间】:2020-10-03 12:44:55
【问题描述】:
我开始使用 Firebase 安全规则。为了测试它,我正在编写一个获取集合的函数,然后从集合中获取文档,然后从文档中获取内容。但是,当我尝试从文档中获取内容时它失败了。函数如下
const testAccess = async () => {
const db = firebase.firestore();
try {
const usersCollection = await db.collection('users');
// console.log('usersCollection: ', usersCollection);
console.log('gets to here?');
const docRef = await usersCollection.doc('10158374072639913');
console.log('gets to here 2?')
const doc = await docRef.get();
console.log('gets to here 3!') // not getting to here!
} catch (e) {
console.log('error is : ', e);
}
}
当我运行 docRef.get() 时,我发现错误是:[FirebaseError:缺少或权限不足。]
我不确定为什么这不符合我的安全规则。
我的规则如下
rules_version = '2';
service cloud.firestore {
match /users/{user} {
allow read: if true;
match /{userInfo=**} {
allow read: if true;
}
}
}
这是我的数据库架构
【问题讨论】:
标签: javascript firebase google-cloud-firestore firebase-security