Firestore规则验证时间戳

cre*_*not 7 firebase google-cloud-firestore firebase-security-rules

我想通过客户端发送Firestore文档的创建时间,并使用Firestore规则验证时间,以避免云函数调用(定价).

脚本

我正在测试客户端对Firestore规则的请求,如下所示:

allow create: if request.resource.data.TIMEFIELD == request.time;
Run Code Online (Sandbox Code Playgroud)

该请求包含一个TIMEFIELD具有时间戳的请求,就像request.time.

问题

显然,请求时间和我在发送请求之前设置为字段的时间不相等,这使得这种比较变得不可能.

以下是request.time文档中的定义.

当服务收到请求时.

我想知道是否有办法在文档中设置一个等于的字段request.time.

由于Flutter存在问题,我无法使用服务器端时间戳.
因此,我需要知道如何验证客户端时间戳,例如time.nowFirestore规则.

cre*_*not 2

这已被实现到 Cloud Firestore 的 Flutter 插件中:

FieldValue.serverTimestamp()
Run Code Online (Sandbox Code Playgroud)

使用它作为字段的值将分配一个等于request.time该字段的时间戳,服务器端。

您可以在的API 参考中找到更多相关信息cloud_firestore