Im trying to update the password in the database firebase with react native It works but I have the error "The password must be 6characters long or more"
I know this is because of the "this.setState({newPassword: "",currentPassword: ""})", but I dont know how to fix it..
export default class ChangePassword extends React.Component {
constructor(props) {
super(props);
this.state = {
newPassword: "",
currentPassword: "",
};
}
reauthenticate = (currentPassword) => {
console.log("currentPassword = "+currentPassword)
var user = firebase.auth().currentUser;
var cred = firebase.auth.EmailAuthProvider.credential(
user.email,
currentPassword
);
return user.reauthenticateWithCredential(cred);
};
OnChangePassword = async () => {
if (this.state.currentPassword === "" || this.state.newPassword === "") {
alert("All the fields are required");
}
else if( this.state.newPassword.length <= 5)
{
alert("Password must contains more than 5 characters");
} else {
try {
await this.reauthenticate(this.state.currentPassword).then(() => {
var user = firebase.auth().currentUser;
user.updatePassword(this.state.newPassword);
const response = firebase.database().ref("Users").child(user.uid);
this.setState({
currentPassword:"",
newPassword:""
})
})
} catch (error) {
console.log(error);
alert(error);
}
}
};
render() {
return (
<View >
<TextInput
secureTextEntry={true}
onChangeText={(currentPassword) =>
this.setState({ currentPassword })
}
/>
<TextInput
secureTextEntry={true}
onChangeText={(newPassword)=>this.setState({newPassword})}
/>
<Button onPress={() => this.OnChangePassword()}/>
</View>
);
}
}
}