Yan*_*Yan 3 firebase google-cloud-firestore
在我的company文档中,我有一个名为 的引用字段owner,它指向一个user文档。在规则中,我试图检查经过身份验证的 uid 是否是公司的所有者:
match /companies/{companyId} {
allow read: if isOwner(resource.data.owner, request.auth.uid);
}
function isOwner(owner, userId) {
return path('/users/' + userId) == owner;
}
Run Code Online (Sandbox Code Playgroud)
我尝试了很多东西,但无法弄清楚如何使这项工作发挥作用。
(我知道使用字符串而不是引用有效,但我更愿意使用引用)
构建路径时,请包含以下前缀:/databases/(default)/documents/. 它是文档完整路径的一部分。
match /companies/{companyId} {
allow read: if isOwner(resource.data.owner, request.auth.uid);
}
function isOwner(owner, userId) {
return path('/databases/(default)/documents/users/' + userId) == owner;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
660 次 |
| 最近记录: |