Firestore安全规则奇怪的行为

问题描述 投票:0回答:1

在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;

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

google-cloud-firestore firebase-security-rules
1个回答
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包含一个数字字符串值,必须将其转换为整数才能进行比较。

© www.soinside.com 2019 - 2024. All rights reserved.