我正在编写一个示例聊天应用程序,但安全读取规则存在问题。我只希望用户在连接到聊天应用程序后可以阅读消息。为此,我在消息中添加了时间戳值。现在我只想要这个时间戳> =用户可以获得此消息的实际时间戳。但这不起作用,因为我无法从父级访问 $msgId (通过推送创建)。这是我的rules.json:
{
"rules": {
".read": false,
".write": false,
"chat": {
".write": false,
".read": false,
"message": {
".write": false,
".read": "data.child($msgId).child('timestamp').val() == now",
"$msgId": {
".write": true,
".validate": "newData.hasChildren(['name','text','timestamp']) && newData.child('timestamp').val() == now"
}
},
}
}