Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda