I am using firebase (with Angularfire) for an html5 phone app. The user inputs only their email in the start screen, and then, depending on whether that email is already reg
A little easier example to understand how to catch if the user already exists when signing up with email / password
.signInWithEmailAndPassword() Example
.createUserWithEmailAndPassword(email, password)
.catch(error => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
// Catch this errorCode to know if user exists
if (errorCode === 'auth/email-already-in-use') {
// Call function X to sign user in instead
signInMail(email, password);
return;
}
// Weak password?
else if (errorCode == 'auth/weak-password') {
console.log('The password is too weak.');
}
else {
console.log(errorMessage);
}
console.log(error);
})
Important part that you want to use in your own code would be this
.catch(error => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
if (errorCode === 'auth/email-already-in-use') {
console.log('This email is already in use');
// Your action
return;
}
})