0

wondering if it is possible to add a delay between onCall requests.

The end goal is to send data to Firestore. I want to reduce abuse such as spam requests, by implementing delays between requests.

If one user sends a request, any "onCall" requests from the same user, should be omitted for the next 10 seconds so I can reduce invocations/ costs. (Returning a message on the user's screen: "Please try again in 10 seconds")


exports.sendToFirestore = functions.https.onCall((data, context, "delay?") => {

//send data to Firestone 


});
Joe
  • 3
  • 2
  • There is no simple configuration for this. You'll have to force each user to correctly identify themselves in their call, persist some information per user about their invocation patterns, and reject the requests that do not meet your requirements. – Doug Stevenson Aug 16 '22 at 00:21
  • Can achieve the backend protection using rxjs client side. E.g. https://github.com/alex-okrushko/backoff-rxjs – Andrew Allen Aug 16 '22 at 00:30
  • If you consider letting the client write directly to Firestore and then triggering a Cloud Function from that, you could do https://stackoverflow.com/questions/56487578/how-do-i-implement-a-write-rate-limit-in-cloud-firestore-security-rules – Frank van Puffelen Aug 16 '22 at 01:41
  • 1
    I would most certainly apply this logic on the client, for a number of reasons. Just timestamp every call (on the client) and don't permit any calls within `n` seconds of each other. – trndjc Aug 16 '22 at 02:57

0 Answers0