0

I want to allow user to post a blog after every 3 hours of the last post.I dont want my daily limit of free plan to be finished up by spams of writes in firestore. How should I start. I am using redux, react, firestore. The objective is to how can I initiate my code and Logic

BQC
  • 23
  • 5
  • When storing a blog to Firestore, why not include the date and time that it was stored? Then, when storing a blog, first check to see if the user has any that were posted within the last 3 hours... And if there are none, allow them to post! – Ryan May 15 '21 at 11:48

1 Answers1

0

You should use the firestore rules to ensure 100% safety. Puf has a great answer to your question here.

If you allow writes to specific users I would recommend to save with a firebase function under users/writetimes/{userUid} the time he createt the last post and when writing again check if the users last timestamp is more than 3h ago.

Something like this:

match /users/{document=**} {
  allow create: if isCalm();
  function isCalm() {
    return request.time > get(/databases/$(database)/documents/users/writetimes/$(request.auth.uid)).data.timestamp + duration.value(3, 'h');
  }
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Tarik Huber
  • 7,061
  • 2
  • 12
  • 18