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

210
Visualizações
How to call more functions on completing user signup?

I am creating a login function with react and firebase, i want to call two more functions on completing signup, I tried doing

  const signUpSubmit = (e,closeSignUpCard,openSignInCard) => {
      e.preventDefault();
      const email = e.target.email.value;
      const password = e.target.password.value;

      signInWithEmailAndPassword(auth, email, password)
        .then(() => {
        closeSignUpCard();
        openSignInCard();
    }
    .catch((error) => {
          alert(error.message);
    });
};

but it shows error:

closeSignUpCard is not defined
openSignInCard is not defined

is there any other way to go about doing this? btw, i'm using firebase:^9.1.0

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

0

You could turn your signUpSubmit function into an async funcion, and just await for the internal promises to end. This way you don't need to get into a callback hell and still things will happen after events you have some kind of control.

Also, if the openSignInCard function must be executed after the closeSignUpCard function, you can turn them into async functions and use await before they are called, so the next one will only be called after the first one ends.

Remember to be careful of using too much awaits. You know, users don't like waiting too much

const signUpSubmit = async (e, closeSignUpCard, openSignInCard) {
   e.preventDefault()
   const email = e.target.email.value
   const password = e.target.password.value

   const signIn = await signInWithEmailAndPassword(auth, email, password)
      .then(r => { return { success: true } })
      .catch(e => { return { success: false, error: e.message })

   if ( signIn.success ){
      closeSignUpCard()
      openSignInCard()
   } else {
      alert(signIn.error)
   }
}
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