Enable password change using updatePassword and reauthenticate (Firebase+Angular)

Viewed 173

I want to allow password change on the site I am building. I used information from stackoverflow and from what I saw on the Internet, before using the updatePassword function it is recommended to reauthenticate ,to verify identification of the user. The following function did not work for me, do you have any idea why?

  auth_state: any = null;

  constructor(private firebaseAuth: AngularFireAuth) {
    this.firebaseAuth.auth_state.subscribe((auth =>{
      this.auth_state= auth;
    }))
  } 
  changePassword(new_password) {
    var credentials =  this.auth_state.prototype.reauthenticateWithCredential.EmailAuthProvider.credential("email@example.com", "oldPassword");
    this.auth_state.prototype.reauthenticate(credentials)
      .then(() => {
        this.auth_state.prototype.updatePassword(new_password)
          .then(() => {
          })
          .catch((error) => {
            console.log(error);
          })
      })
      .catch((error) => {
        console.log(error);
      })
  }

the erorr I got was:

ERROR TypeError: Cannot read property 'reauthenticateWithCredential' of undefined
0 Answers
Related