【发布时间】:2018-08-16 14:52:11
【问题描述】:
我正在尝试为我的 Firestore 数据库创建一些规则。当我在 firebase 控制台的模拟器中运行这些规则时,一切正常。然而,当我部署规则并在我的网站上试用时,我在控制台中收到权限被拒绝错误。
我试图访问的数据是这样存储的:
1. /teams/{teamId}
2. /teams/{teamId}/boards/{boardId}
{teamId} 和 {boardId} 是自动生成的 ID:
例如:
/teams/JTUrZcqz9Z20JuyCCcnV
/teams/JTUrZcqz9Z20JuyCCcnV/boards/OfcLPZItCk6Li7OeXwwt
我正在尝试遍历所有这些孩子。
firestore.rules:
match /teams/{teamId} {
allow read: if isMemberOfTeam(teamId);
allow write: if true; // memberOfTeam(teamId);
match /boards/{boardID} {
allow read: if memberOfTeam(teamId) || boardIsPublic(teamId);
allow write: if memberOfTeam(teamId);
match /{document=**} {
allow read: if memberOfTeam(teamId) || boardIsPublic(teamId);
allow write: if memberOfTeam(teamId);
}
}
match /{document=**} {
allow read: if isMemberOfTeam(teamId); // memberOfTeam(teamId);
allow write: if true; // memberOfTeam(teamId);
}
}
function isMemberOfTeam(teamId) {
return get(/databases/$(database)/documents/teams/$(teamId)).members[request.auth.uid].isMember;
}
function boardIsPublic(teamId) {
return get(/databases/$(database)/documents/teams/$(teamId)).data.isPublic;
}
网站代码: Firestore 查询:
ref.where('members.' + user.uid + '.isMember', '==', true)
所有代码:
this.teamsCollection = this.auth.user$.filter(user => user != null)
.map(user => this.afs.collection<TeamsInterface>('teams', ref => ref.where('members.' + user.uid + '.isMember', '==', true)))
.shareReplay(1);
this.$teams = this.teamsCollection.switchMap(collection => collection.snapshotChanges().map(actions => {
return actions.map(a => {
const data = a.payload.doc.data() as TeamsInterface;
data.id = a.payload.doc.id;
return data;
});
}));
我在控制台中遇到错误:
权限缺失或不足。
【问题讨论】:
-
请附上您用来测试的代码。
标签: firebase google-cloud-firestore