I have a counter in my firebase to count likes in each post.
var databaseRef = firebase.database().ref('/posts/').child(pid).child('likes');
databaseRef.transaction(function(count) {
so this will add +1 in each like in posts/likes after I insert it in likes/postid/userid json. To count the likes.
I made a rule for this, to allow count +1 like per time:
"likes": {
".write": "newData.isNumber() &&
((!data.exists() && newData.val() === 1) || newData.val() === data.val()+1)"
},
it avoid someone to put 1000 likes in a post at once, but not protect someone to run a script inserting +1 like each second... any solution for this? how to protect a counter in firebase rules?