Firestore安全规则异常行为

时间:2019-04-25 11:59:44

标签: google-cloud-firestore firebase-security-rules

在Firestore安全规则中,以下行适用于读取操作,以在整数 resource.data.uids 数组中找到 request.auth.uid

allow read: if request.auth.uid in resource.data.uids;

但是以上行不适用于更新操作。我必须将 request.auth.uid 转换为整数,以使其可用于更新操作,如下所示:

allow update: if int(request.auth.uid) in resource.data.uids;

我想知道这种奇怪行为的原因。

1 个答案:

答案 0 :(得分:0)

uid中使用的.where("uids", "array-contains", uid)的数据类型更改为整数后,读取和更新操作现在可以在以下行中使用:

allow read, update: if int(request.auth.uid) in resource.data.uids;

现在看起来一切正常,因为resource.data.uids包含一个整数数组,而request.auth.uid包含一个数字字符串值,必须将其转换为整数才能进行比较。