【发布时间】:2019-06-15 12:25:27
【问题描述】:
我已经编写了这些 Firestore 安全规则,只允许获得批准的用户使用数据:
service cloud.firestore {
match /databases/{database}/documents {
match /bikes/{document} {
function getRole(role) {
return get(/databases/$(database)/documents/employees/$(request.auth.uid)).data.isApproved
}
allow read: if getRole() == true;
allow write: if getRole() == true;
}
}
}
但出现此错误
core.js:12501 ERROR 错误:权限缺失或不足。 在新的 FirestoreError (index.cjs.js:346)
怎么了?
附加代码:
1) 角度代码
getUserData() {
this.afAuthState.authState.subscribe(user => {
console.log(user)
console.log("user uid")
console.log(user.uid)
if (user) {
this.dao.getEmployeeByUID(user.uid).subscribe( res => {
if (res) {
console.log(res)
this.employee = res
this.role = this.employee.role
}
else console.log("please ask the admin for confirmation")
})
}
else console.log("please login")
})
}
当我应用规则时,我无法获取此 (getEmployeeByUID) 数据。当没有规则时 - 很好
【问题讨论】:
-
请编辑您的问题以包含触发此错误的最小独立代码。最好查看定义用户角色的文档。见how to create a minimal, complete, verifiable example。
标签: angular google-cloud-firestore angularfire2 firebase-security