Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

305
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda