如何验证 servertimestamp 是否小于 Firebase 本身的某个值?
How to validate servertimestamp is less than a certain value in Firebase itself?
我需要有关此 Firebase 规则的帮助,我有此 child 用于存储时间戳
而且我只需要在服务器时间戳小于存储在日期-> 日期 child 上的时间戳时允许写入 firebase 的另一个位置。
我不确定该怎么做,是写入还是验证,或者如何获取规则以读取 Firebase 本身的特定值。
{
"rules": {
"test":{
".read" : false,
this-->".write": "now < root.child('date\Date')",
or this-->".validate": "now < root.child('date\Date')"
}
}
}
更新
我现在可以从一个位置读取,但问题是转换 comarison 的值。
我尝试了 (int) (Integer) parseInt() Number() 但它们都失败了
我走在正确的轨道上还是应该采取不同的方式?
更新 2
我设法编写了一个可接受的规则 - 不会产生错误 - 但它不起作用,这里是
{
"rules": {
"test":{
".write": "now < root.child('date/Date').val()",
".read" : false
}
}
}
有什么建议吗?
更新 3
实际上它并没有很好地工作,我认为它是将来自 'now' 函数的数字与来自 root.child.val 的字符串进行比较,所以规则总是错误的。
我设法解决了这个问题,将解决方案放在这里以防其他人需要它
"rules": {
"test":{
".write": "now + ' ' < root.child('date/Date').val() + ' '",
".read" : read
}
}
所以基本上我将 (+ ' ') 添加到 now 以将其转换为字符串,并将其添加到 val 只是为了使两个字符串比较相同的长度。
安全规则可以读取您的 Firebase 数据库中的数据。如果将 now
变量与 root
变量结合使用,则可以检查时间戳。
{
"rules": {
"test":{
".write": "now < root.child('date').child('Date').val()",
".read" : "now < root.child('date').child('Date').val()"
}
}
}
然后在你的代码中,你需要监听取消回调:
var ref = new Firebase("<my-firebase-app>/test");
ref.on('value', function(snap) {
console.log(snap.val());
}, function(error) {
// if permission is denied the error will log here
console.error(error);
});
Check out the Firebase API reference for more info.
此外,使用 Firebase 应用面板中的模拟器应该可以帮助您测试规则:
我需要有关此 Firebase 规则的帮助,我有此 child 用于存储时间戳
而且我只需要在服务器时间戳小于存储在日期-> 日期 child 上的时间戳时允许写入 firebase 的另一个位置。 我不确定该怎么做,是写入还是验证,或者如何获取规则以读取 Firebase 本身的特定值。
{
"rules": {
"test":{
".read" : false,
this-->".write": "now < root.child('date\Date')",
or this-->".validate": "now < root.child('date\Date')"
}
}
}
更新
我现在可以从一个位置读取,但问题是转换 comarison 的值。 我尝试了 (int) (Integer) parseInt() Number() 但它们都失败了
我走在正确的轨道上还是应该采取不同的方式?
更新 2 我设法编写了一个可接受的规则 - 不会产生错误 - 但它不起作用,这里是
{
"rules": {
"test":{
".write": "now < root.child('date/Date').val()",
".read" : false
}
}
}
有什么建议吗?
更新 3
实际上它并没有很好地工作,我认为它是将来自 'now' 函数的数字与来自 root.child.val 的字符串进行比较,所以规则总是错误的。
我设法解决了这个问题,将解决方案放在这里以防其他人需要它
"rules": {
"test":{
".write": "now + ' ' < root.child('date/Date').val() + ' '",
".read" : read
}
}
所以基本上我将 (+ ' ') 添加到 now 以将其转换为字符串,并将其添加到 val 只是为了使两个字符串比较相同的长度。
安全规则可以读取您的 Firebase 数据库中的数据。如果将 now
变量与 root
变量结合使用,则可以检查时间戳。
{
"rules": {
"test":{
".write": "now < root.child('date').child('Date').val()",
".read" : "now < root.child('date').child('Date').val()"
}
}
}
然后在你的代码中,你需要监听取消回调:
var ref = new Firebase("<my-firebase-app>/test");
ref.on('value', function(snap) {
console.log(snap.val());
}, function(error) {
// if permission is denied the error will log here
console.error(error);
});
Check out the Firebase API reference for more info.
此外,使用 Firebase 应用面板中的模拟器应该可以帮助您测试规则: