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

112
Visualizações
How to call a second function within async google cloud function

I'm trying to use the firebase admin SDK to add users with specific roles. I can get it working where newly added users are authenticated, but I also need to create a users/id record in my firestore database.

Here is my code:

exports.createUser = functions.https.onCall(async (data, context) => {
  const user = await admin.auth().createUser({
    email: data.email,
    emailVerified: true,
    password: data.password,
    displayName: data.displayName,
    disabled: false,
  });
  await admin.firestore().collection('users').doc(user.uid).set({
    displayName: user.displayName,
    id: user.uid,
    email: user.email,
    role: 'clientAccess',
    created: fb.firestore.FieldValue.serverTimestamp()
  })
  return { response: user }
});

Where can I put the return admin.firestore().col... part to make this work?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm going to suggest that you're not quite asking the right question. Your task at hand is this:

  1. Create the user account
  2. Add a document to firestore with information about that user
  3. Send the user object back to the calling client.

You don't need at all return for task 2. You just need a return for step 3. You can simply use async/await on each of the functions that return a promise to make sure they are all executed and completed in the right order before the function returns the final result to the client.

    const user = await admin.auth().createUser({ ... });
    await admin.firestore().collection('users').doc(user.uid).set({ ... })
    return { response: user }

You probably also don't nee to worry about try/catch unless you have some special error handling.

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