比较request。在Firestore规则中使用tomillis()的time到值集的值?

发布于 2025-01-29 06:57:21 字数 578 浏览 2 评论 0原文

我有以下代码,我想比较2个值并相应地设置规则,但是显然两者之间没有一致性,至少比较没有工作问题,我想使所有时间戳存储在MS中。

// Data Filed set in cloud fuction.
const expiresIn = 3600; // test 1h   //172800  === 48h
const createdAt = admin.firestore.Timestamp.now().toDate();
createdAt.setSeconds(createdAt.getSeconds() + expiresIn);

premiumUntill: admin.firestore.Timestamp.fromDate(createdAt).toMillis()


// Rules
&& request.auth.token.premiumUntill > request.time
&& resource.data.premiumUntill > request.time

I have the following code and I want to compare 2 values and set rules accordingly, but apparently there is no consistency between the two, at least the comparation is not working issue was I want to make all timestamps stored in ms.

// Data Filed set in cloud fuction.
const expiresIn = 3600; // test 1h   //172800  === 48h
const createdAt = admin.firestore.Timestamp.now().toDate();
createdAt.setSeconds(createdAt.getSeconds() + expiresIn);

premiumUntill: admin.firestore.Timestamp.fromDate(createdAt).toMillis()


// Rules
&& request.auth.token.premiumUntill > request.time
&& resource.data.premiumUntill > request.time

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由如风 2025-02-05 06:57:21

request.time time 是a timestamp 对象,而不是米利斯的时间。它不能直接与整数相提并论。

如果您想使用请求。在规则中,应将firestore时间戳对象存储在文档字段中以进行直接比较。或者,您可以将规则时间戳转换为MILLIS,然后将其与整数进行比较。

request.time is a Timestamp object, not time in millis. It's not directly comparable to an integer.

If you want to use request.time in rules, you should store a Firestore Timestamp object in the document field for direct comparison. Or you can convert the rules Timestamp to millis first before comparing it to an integer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文