【发布时间】:2020-05-18 12:50:53
【问题描述】:
我有以下数据库规则:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isAdmin() {
return get(/databases/$(database)/documents/administrators/$(request.auth.uid)).data.admin == true;
}
match /users/{userId}/{document=**} {
allow read: if request.auth.uid != null;
allow write: if request.auth.uid == userId;
}
match /administrators/{document=**} {
allow read, write: if isAdmin();
}
match /projects/{project} {
function getRole(rsc) {
return rsc.data.members[request.auth.uid];
}
allow create: if request.auth.uid != null;
allow read: if request.auth.uid != null && ( getRole(resource) == 'owner' || getRole(resource) == 'participant' );
allow write: if request.auth.uid != null && ( getRole(resource) == 'owner' );
}
match /statuses/{document=**} {
allow read: if request.auth.uid != null;
allow write: if isAdmin();
}
}
}
当我使用经过身份验证的 userId 测试读取集合 projects 的文档时,一切都很好。 当我尝试使用 AngularFire 读取同一个集合时,我收到错误 FirebaseError: Missing or enough permissions。
this.projectsCollection = this.afs.collection<Project>('/projects', ref =>
ref.orderBy('projectId'));
this.projects = this.projectsCollection.valueChanges();
this.projects.subscribe(data => {
this.isLoading = false;
}, error => {
this.isLoading = false;
console.log(error);
})
您能帮我找出错误吗? 谢谢
【问题讨论】:
标签: javascript google-cloud-firestore firebase-authentication firebase-security angularfire2