【发布时间】:2018-05-14 06:42:59
【问题描述】:
我正在尝试在我的 firestore 数据库中构建类似基于角色的访问 (https://firebase.google.com/docs/firestore/solutions/role-based-access)。但是像我定义的角色不起作用。我总是收到错误
Missing or insufficient permissions.
到目前为止,我的 Firestore 规则中有以下内容:
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
function getRole(rsc) {
return rsc.data.roles[request.auth.uid];
}
function isOneOfRoles(rsc, array) {
return isSignedIn() && (getRole(rsc) in array) || isSignedIn() && rsc.data.openWorld == true;
}
match /users/{user} {
allow read: if isSignedIn() && request.auth.uid == resource.data.uid;
}
// Match any document in the 'worlds' collection
match /worlds/{world} {
allow read: if isOneOfRoles(resource, ['owner', 'writer', 'commenter', 'reader']);
}
}
}
我的文档结构如下:ROOT/worlds/{WORLDID}/... 以及其中的每个文档如下:
{
name: "Open World",
desc: "",
openWorld: true,
roles: {
DzpqsN6QjmZoCoM0eymWJ17VKbG3: "owner"
}
}
我将它与 Angular Frontedn 和 Angularfire 一起使用,其中包含以下代码,这些代码被包装到服务中:
getWorlds(userId): Observable<any> {
return this.afs.collection('worlds').snapshotChanges().map(actions => {
return actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return { id, ...data };
});
}).catch((e: any) => Observable.throw(this.errorHandler(e)));
}
任何人都可以看到那里可能存在错误,或者此时 Firestore 是否存在一般错误?谢谢!
【问题讨论】:
-
您还应该包括用于测试的读/写数据/代码。
标签: javascript firebase google-cloud-firestore