I am trying to build a function that allows user to change their password. The problem is when I am getting the current user's data it shows that the email is null.
Everything works on Firebase, users are creating in Firebase auth system.
Here is a part of my code
reauthenticate = (currentPassword) => {
var user = firebase.auth().currentuser;
var cred = firebase.auth.EmailAuthProvider.credential(user.email, currentPassword);
user.reauthenticateWithCredential(cred);
}
reauthenticate(currentPassword).then(() => {
var user = firebase.auth().currentuser;
user.updatePassword(newPassword).then(() => {
alert("Password changed");
window.location.replace("./index.html");
}).catch((error) => {
console.log(error);
})
});
What console shows is Uncaught TypeError: Cannot read properties of undefined (reading 'email') at reauthenticate (password.js:15:64) at changePassword (password.js:27:9)
its currentUser not currentuser. Capital U.
const user = firebase.auth().currentUser;