Firestore规则中的WriteFields仅在模拟器中有效 [英] WriteFields in Firestore Rules only working in Simulator
问题描述
我使用Firestore Rules时遇到的一个大问题是,在Firebase控制台中使用模拟器来模拟数据库访问与我从客户端看到的行为不符.现在,我偶然遇到了一个似乎无法解决的问题.
问题
在模拟器中,以下语法正常工作:
allow create: if request.writeFields.hasAll(["a", "b", "c"]);
当从我的Android客户端请求完全相同字段时,我得到Error performing setData, PERMISSION_DENIED: Missing or insufficient permissions.
.
请求(简化)如下:
通过设置allow create;
(简化),我已经验证并确定问题必须与request.writeFields
相连,因为一旦添加有关此的逻辑,我的请求(仅来自真实客户的请求)就会失败. >
在我的所有测试中,允许进行模拟数据访问.
我的参考是 List
界面.>
问题
我想知道我是否缺少有关> c4> (可能连接到allow create
),以及如何定期查看模拟访问与实际访问之间的差异.
请记住,我的语法在模拟器中工作得很好,但是包含完全相同的JSON数据的真实请求失败.
您现在可以使用地图差异而不是writeFields来解决此问题:
request.resource.data.diff(resource.data).affectedKeys().hasAll(["a", "b", "c"]);
A big problem I am having with Firestore Rules is that using the Simulator in the Firebase Console to simulate database accesses does not correspond to the behavior I am seeing from my clients. Now I have stumbled accross an issue that I cannot seem to fix.
Issue
The following syntax works fine in the simulator:
allow create: if request.writeFields.hasAll(["a", "b", "c"]);
When requesting with the exact same fields from my Android client, I get Error performing setData, PERMISSION_DENIED: Missing or insufficient permissions.
.
The request (simplified) looks as follows:
By setting allow create;
(simplified) I have verified and identified that the problem has to be connected to request.writeFields
because my requests, only from my real clients, fail as soon as I add logic regarding that.
The simulated data access is allowed in all my tests.
My reference is the List
interface.
Question
I am wondering if I am either missing something about writeFields
(potentially connected to allow create
) and also how I am regularly seeing disparities between simulated and real accesses.
Keep in mind that my syntax works perfectly fine in the simulator, but a real request containing the exact same JSON data fails.
You can now use map diffs to solve this issue instead of writeFields:
request.resource.data.diff(resource.data).affectedKeys().hasAll(["a", "b", "c"]);
这篇关于Firestore规则中的WriteFields仅在模拟器中有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!