【发布时间】:2018-04-02 06:22:48
【问题描述】:
我有一个简单的用户集合,文档 id 使用带有名称字符串的 uid
我正在使用 angularfire2 连接到集合
this.users = afs.collection<User>('users').valueChanges();
我正在使用 Firebase 身份验证。显示用户 ID 时,我得到与用户文档匹配的 4NxoeUeB4OXverhHhiw86eKl0Sj1。
this.afAuth.authState.subscribe(auth => console.log(auth.uid));
我正在尝试为集合添加规则。如果我使用以下规则,我会收到错误 Missing or enough permissions。
`service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth.uid == userId;
}
}
}`
如果我将规则更改为 request.auth != null,则会显示数据。
`service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth != null;
}
}
}`
我做错了什么?我也在尝试一些不同的规则,例如。 resource.data.name != null。它也不起作用。
我正在测试规则。最终结果我想要一个 reader 数组字段和 writers 数组字段,这样我就可以尝试类似request.auth.uid in resource.data.readers 来控制对文档的访问
【问题讨论】:
标签: firebase google-cloud-firestore