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

243
Views
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
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!