Reputation: 33
Hello I'm trying to reauthenticate the user before they delete their account but I'm having one problem I can't seem to solve; how do I obtain the user's password if I didn't save it since that would be a privacy issue. I've seen other posts about this but they don't mention how they got the password. This is my code for deleting account:
const onDeleteAccountPress = () => {
firebase.database().ref('users/'+userId).remove()
var userReauth = firebase.auth().currentUser
const credential = firebase.auth.EmailAuthProvider.credential(userReauth.email,userProvidedPassword)
userReauth.reauthenticateWithCredential(credential)
for(let i =0; i < goalCounter; i++){
firebase.database().ref('goals/'+(courseGoals[i].id)).remove()
}
userReauth.delete()
.then(function(){
props.navigation.navigate('Login');
props.navigation.reset({ index: 0, routes: [ { name: 'Login' } ] });
}).catch(function(error){
console.log(error)
console.log('there is something wrong')
})
}
Upvotes: 0
Views: 356
Reputation: 80914
When the user logs in, you can store the password inside localStorage
, then if the user wants to delete the account, you can get the password from the storage and pass it to the EmailAuthProvider.credential()
method.
Upvotes: 0