function signUp(){
var email = document.getElementById("email");
var password = document.getElementById("password");
const promise = auth.createUserWithEmailAndPassword(email.value, password.value);
promise.catch(e => alert(e.message));
alert("Signed Up");
}
I have this code here that when a valid email and password are entered the user presses a button and signs the user up. But when the user enters invalid data the alert("Signed Up") displays along with the error message, is there any way to avoid that?
As written, the "Signed Up" alert runs immediately, before the createUser is complete, whether or not it succeeds. The way to use promises is to put the code that should execute after successful completion in a then
block, and the error handling -- as you have it -- in a catch...
const promise = auth.createUserWithEmailAndPassword(email.value, password.value);
promise.then(() => alert("Signed Up")).catch(e => alert(e.message));