I am implementing a login functionality with firebase and React Native and keep getting this error when I use async method:-
[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) => {
try{
auth.signInWithEmailAndPassword(email, password)
.catch(function(error) {
console.log(error);
return fail("failed");
})
}catch(e){
return fail("An error occurred");
}
Edit: I removed the try catch blocks and did:
auth.signInWithEmailAndPassword(email, password).catch(function(error) { console.log(error); return fail("failed");})
return succeed();
This seems to have solve that error but now my code is always returning succeed(). Any thoughts?