The promise state is whether the promise resolves or rejects. If you're using the .then
approach to working with promises, you can supply a second callback function to handle the error case:
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(status => {
// If it gets to here, the promise resolved
console.log(status);
}, error => {
// If it gets to here, the promise rejected
console.log(error);
});
// Or, equivalently:
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(status => {
console.log(status);
})
.catch(error => {
console.log(error);
});
If you're using async/await, then you handle the error case with a try/catch
async someFunction() {
try {
const status = await firebase.auth().createUserWithEmailAndPassword(email, password);
// If it gets to here, the promise resolved
console.log(status);
} catch (error) {
// If it gets to here, the promise rejected
console.log(error);
}
}