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

123
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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