Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda