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

165
Visualizações
Async method always returning true

I am implementing a login functionality with firebase and React Native. The handleLogin method is always returning succeed(). If I remove the success(), I get :

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'result2.failed')]

export default async function login(credentials) {
    let result2= succeed();
    result2 = await handleLogin(credentials.email, credentials.password);
    if(result2.failed()){
       return fail({password: "Login failed"});
    }
    else{          
       return succeed();
    } 
}

const handleLogin = async(email,password) => {
    auth.signInWithEmailAndPassword(email, password)
    .catch(function(error) { 
         console.log(error); 
         return fail("failed");
     })

     return succeed(); // or fail() in which case method always returns fail()
         

I have also tried using .then() but I keep getting object undefined error if I don't return succeed() or fail() in the end of handleLogin():

auth.signInWithEmailAndPassword(email, password)
    .then(function(){return succeed();})
    .catch(function(error) { 
        console.log("we fail"+error); 
        return fail("failed");
    })
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I solved the problem by adding a return statement:

return auth.signInWithEmailAndPassword(email, password).then(function(){return succeed();}).catch(function(error) { return fail("Login Attempt Failed\n"+error);})
about 4 years ago · Juan Pablo Isaza Relatório

0

Its a known issue of the firebase. Similar thing happened to me on angular code.

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