比较request。在Firestore规则中使用tomillis()的time到值集的值?
我有以下代码,我想比较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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.