I have small problem, but I don't know what I doing wrong. I have function like below. In .catch alert working ok and I see error in browser, but I have problem with this same error in console.log <- I don't see anything Basically, I wanted to pass error to another function like notify(error) but I don't see anything.
const signIn = (e) => {
e.preventDefault();
signInWithEmailAndPassword(auth, email, password)
.then(() => {
navigate("/");
})
.catch((error) => {
// notify(error)
console.log("error: ", error);
alert(error);
});
};
I try doing try catch and async await but I have the same problem:
async function signIn(e) {
try {
e.preventDefault();
await signInWithEmailAndPassword(auth, email, password).then(() => {
navigate("/");
});
} catch (error) {
// notify(error);
console.error("error: ", error);
alert(err);
}
}
You can not call error object directly in console.log as js has some issues parsing error as a JSON object. Instead, use
error.messageorerror.toString()innotify()function. Error object has breaks that cause issues when parsing to a JSON object. Check below code, onlyerror.messagethat is the first line (key : value pair) of the object is accessible. Notice thatJSON.parse(error)gives an error because of this.