【发布时间】:2021-09-06 18:43:40
【问题描述】:
我有一个帖子集合,其中包含这种结构的帖子文档:
{
title: "test title"
...
authorUid: "testuid"
}
我想添加一个安全规则,它只允许具有 uid 的经过身份验证的用户将具有相同 authoUid 的文档添加到此集合中。
我试过这个 -
match /posts/{postId} {
allow read: if true;
allow create: if signedInUserIsPostAuthor();
}
function signedInUserIsPostAuthor(){
return request.auth.uid == request.resource.data.authorUid;
}
但这似乎失败了。我假设经过身份验证的用户(request.auth.uid)应该等于写入之前的文档(request.resource.data)。
但这不起作用。任何线索我错过了什么?
【问题讨论】:
-
您能否编辑您的问题以包含失败的(最少)实际代码?还请确保代码证明符合规则,例如:登录当前用户,并且您将其 UID 写入
authorUid。
标签: firebase google-cloud-firestore firebase-security