I am having an issue when trying the following validation rule:
".validate": "newData.val() >= now - 2000 && newData.val() >= data.parent().parent().parent().parent().parent().child('users/'+auth.uid+'/lastPostAt').val() - 2000"
Here are the relevant area's of my Firebase database schema:
areas
-> area1
-> posts
-> uid
-> post object ( has timestamp property (date) - firebase timestamp)
user
-> uid
-> user object ( has timestamp property (lastPostAt) - Firebase timestamp)
When a post is submitted it updates the lastPostAt
timestamp property in the user object for the specific user that submitted the post.
What I am looking for is some Firebase rules to ensure that when a new post is submitted that it is not stored unless the user has not submitted another post within the last 2 minutes.
I have look at this post on StackOverflow, but I am trying to see if it is possible to do this with my implementation.
Under the $uid
for my posts node, I am trying a .validate
rule:
"posts" : {
"$message_id": {
".indexOn": "username",
".write": "newData.hasChildren(['date'])",
"date" : {
".validate": "newData.val() >= now - 2000 && newData.val() >= data.parent().parent().parent().parent().parent().child('users/'+auth.uid+'/lastPostAt').val() - 2000"
}
Currently, when I submit a post, both the timestamps are the same, but I can keep posting more and more posts with no delay.