Here is my code:
function loginWithEmailHandler() {
signInWithEmailAndPassword(auth)
.then((result) => {
const user = result.user;
console.log(user.email, user.displayName);
navigate("/");
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
setMode("INCORRECT");
console.log(errorCode, errorMessage);
});
}
When I run this function in my LoginForm.js it gives the error stated in the title. I don't know how I could check if it checking for the correct email or not so I am a bit stuck here.
CodePudding user response:
The signInWithEmailAndPassword()
takes 3 parameters - auth instance, email and password. But you are passing only the first one. Try refactoring the code as shown below:
function loginWithEmailHandler(email, password) {
signInWithEmailAndPassword(auth, email, password)
.then((result) => {
const user = result.user;
console.log(user.email, user.displayName);
navigate("/");
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
setMode("INCORRECT");
console.log(errorCode, errorMessage);
});
}
Make sure you pass the email and password entered by the user in that function:
// While calling the function
loginWithEmailHandler('[email protected]', 'userPassword');
You can read more in the documentation.