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

114
Views
Firebase admin sdk calling the wrong catch

I am trying to add a new user with firebase-admin and then to save a new document in a custom collection.

Sample code following:

admin.auth().createUser(user)

    .then((record) => {

       user.uid = record.uid;

       userCollection.doc(record.uid).set({...user})

           .then(writeResult => {
               resolve();
           })
           .catch(reason => {
               reject(reason)
           });
    })
    .catch((err) => {
        reject(err);
    });

The problem is, if the userCollection.doc(record.uid).set({...user}) fails, I expect the nested catch (with reason as param) to be called. Instead, always the outer one is called (with err as param).

Is there something wrong with the SDK or am I doing something wrong?

Thank you

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is because you don't return the promise returned by userCollection.doc(record.uid).set() and therefore you don't return the promises returned by the subsequent then() and catch() methods. In other words you don't return the promises chain.

But, actually, you should chain your Promises as follows and avoid a then()/catch() pyramid.

  admin
    .auth().createUser(user)
    .then((record) => {
      user.uid = record.uid;

      return userCollection
        .doc(record.uid)
        .set({ ...user })
    })
    .catch((err) => {

      // Here you catch the potential errors of 
      // the createUser() AND set() methods

      console.log(JSON.stringify(err));

    });

More details here, here and here.

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