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

244
Visualizações
Stop Firebase Function If Error Was Thrown

I'm building fairly lengthy firebase cloud functions, and to make the code more readable, I'm splitting some verifications into different files.

For instance, when a user wants to make a change, I check whether their account status is set to activated. I offload that logic into a separate authFunctions.js file, and if the user does not pass, I throw an error directly from within the authfunctions.js file.

I've just noticed however that throwing the error from this imported file doesn't stop the calling function from proceeding, and hence a user is able to bypass the security.

index.js

exports.setDraftOrganisation = functions.https.onCall(async (data, context) => {
    // Check if user's account is not disabled (or pending info confirmation)
    authFunctions.validateUserAccountIsActive()

    // Proceed with operation
    updateData()
})

authFunctions.js:

exports.validateUserAccountIsActive = async function() {    
    if(verificationFailed) {
        const functions = require('firebase-functions')
        functions.logger.error(`User's account is not activated`)
        throw new functions.https.HttpsError('failed-precondition')
    }
}

Is there any elegant way to not halt the main function if the imported function signals a blocking issue? I was thinking of maybe using try {} catch(){} in the main function, but that would add a lot more lines of code in the main function effectively defeating the purpose of moving the logic into authFunctions.js.

about 4 years ago · Juan Pablo Isaza
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