gpt4 book ai didi

firebase - Firestore 安全规则 : If timestamp (FieldValue. serverTimestamp) 现在等于

转载 作者:行者123 更新时间:2023-12-01 22:28:55 25 4
gpt4 key购买 nike

如何检查客户端用户是否仅使用 firebase.firestore.FieldValue.serverTimestamp() 创建文档?

我有以下内容:

allow create: if request.resource.data.timestamp == ??

我应该用什么来代替??。我尝试过 serverTimestamp() firebase.firestore.FieldValue.serverTimestamp()nownow() 但是它不起作用。

可以在 Firebase 中这样做:

".validate": "newData.child('timestamp').val() === now"

我正在寻找相同的解决方案。有任何想法吗?谢谢

最佳答案

您可以使用 request.time 属性 ( docs ) 访问安全规则中的当前请求时间戳,该属性在 Firestore 中相当于实时数据库的 now。因此你会想要这样的东西:

allow create: if request.resource.data.timestamp == request.time;

对于serverTimestamp(),这应该评估为true。

应该始终验证安全规则中的客户端输入,即使您使用serverTimestamp()。安全规则不会自动知道服务器而不是客户端输入值,因此如果没有此检查,恶意客户端可能会创建不同的值。

关于firebase - Firestore 安全规则 : If timestamp (FieldValue. serverTimestamp) 现在等于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48783812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com