在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;
我想知道这种奇怪行为背后的原因。
将uid
中使用的.where("uids", "array-contains", uid)
的数据类型更改为整数后,读取和更新操作现在都可以使用以下行:
allow read, update: if int(request.auth.uid) in resource.data.uids;
事情看起来很正常,因为resource.data.uids
包含一个整数数组,而request.auth.uid
包含一个数字字符串值,必须将其转换为整数才能进行比较。