Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

303
Views
Firebase cloud function security using triggers without resulting in infinite loop?

I'm trying to implement some security checks to my cloud function triggers, but as I discovered my current set up results in an infinite loop from the onCreate and onDelete triggers when doc is not valid. How would I go about using onCreate and onDelete triggers for security without resulting in an infinite loop or is there another way that can achieve this without using firestore security rules?

  export const createEventTrigger = functions.firestore.document("events/{id}").onCreate(async (snapshot, context) => {

    const event = snapshot.data() as Event;

    const isValid = await isEventDocumentCreateValid(context, event);

    if (!isValid) {
      // Delete the document if it’s invalid
      console.log(
        `Deleting invalid document for user ${getInvokerUid(context)}`
      );
      await snapshot.ref.delete();
    }
  });
  export const deleteEventTrigger = functions.firestore.document("events/{id}").onDelete(async (snapshot, context) => {
    // Contents of the document as a JavaScript object
    const event = snapshot.data() as Event;

    const isValid = await isEventDocumentDeleteValid(context, event);

    if (!isValid) {
      // Add back the document if it’s invalid
      console.log(
        `Adding back doc after invalid document delete for user ${getInvokerUid(
          context
        )}`
      );
      await snapshot.ref.set(event);
    }
  });
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!