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

189
Visualizações
Return value is null when return value is placed inside the .then function?

I've been trying to fix the following issue for the past two days. I want to create a user and after that return a list as shown below:

exports.createUser = functions.https.onCall((data,context) => {
  try {
    admin.auth().createUser({
      email: "kevin3928@gmail.com"
      password: "a3tbmz"
    }).then((arg) => {
    // a) if I return a variable here it doesn't work
    });
    // b) if I return a variable here it works
  }
});

Returning a variable using method b) it works but I need to return the variable using method a). I can't use async and await because I will receive the following error:

 error  Parsing error: Unexpected token =>

✖ 1 problem (1 error, 0 warnings)

I appreciate it if someone can help me with this, I spent the entire weekend trying to solve this...

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

0

You need to return a value from the top-level code of your function, otherwise Cloud Functions may/will terminate your code before the asynchronous operation has completed.

exports.createUser = functions.https.onCall((data,context) => {
  try {
    return admin.auth().createUser({
      email: "kevin3928@gmail.com"
      password: "a3tbmz"
    }).then((arg) => {
      return "result";
    }).catch((err) => {
      return err;
    });
  }
});

Also see the second code snippet in the documentation on sending back the result, which does something similar.

about 4 years ago · Juan Pablo Isaza Relatório

0

try

let userCreated = false

exports.createUser = functions.https.onCall((data,context) => {
  try {
      admin.auth().createUser({
      email: "kevin3928@gmail.com"
      password: "a3tbmz"
    })
userCreated = true

if(userCreated){
  return // the object you wanted to return
}

  } catch(err){
     throw new Error(err)
}
});
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