Ha Hadi
Ha Hadi

Reputation: 83

Property 'sendEmailVerification' does not exist on type 'void'

I am trying to send an email verification, and then set the data.uid to user.id, no matter where i put promise there is always an error.

Here is my code

onCreate(form: NgForm) {
var user = new User();
user.name = form.value.name;
user.email = form.value.email;
user.contact = form.value.contact;
if(form.value.gender == "male") {
  user.gender = "male";
} else {
  user.gender = "female"
}
let loading = this.mProv.getLoader('Creating your account...', 0);
loading.present();
var promise = this.afAuth.auth.createUserWithEmailAndPassword(form.value.email, form.value.password)
  .then(data => {
    user.id = data.uid;
    this.userProvider.addUser(user)
      .then(_ =>
        loading.dismiss()
      )
      .catch(error => {
        console.log(error);
        loading.dismiss();
        this.mProv.showAlertOkMessage('Error','Sign up error. Please try again later.');
      });
  })
  .catch(error => {
    console.log(error);
    loading.dismiss();
    this.mProv.showAlertOkMessage('Error','Sign up error. Please try again later.');
  });
  promise.then(function(user) {
    user.sendEmailVerification();

    // firebase.auth().currentUser.sendEmailVerification();

  }, function(error) {
    console.log(error)
  })
}

Error messages = Property 'sendEmailVerification' does not exist on type 'void'.

enter image description here

If i put promise after .createUserWithEmailAndPassword

Error messages = Property 'uid' does not exist on type 'void'.

enter image description here

Upvotes: 3

Views: 608

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222542

Typescript complains that uid does not exist on type void, probably try changing it as follows,

.then((data:any)=>{
   user.id = data.uid;
}

Upvotes: 1

Related Questions