0

Currently we are working on the sign in with firebase auth. It is working fine. Now we are trying to show the user error messages for example when the email address they want to use for registering the account is already linked with another account. Or when their password is not complex enough. The ts code looks like this.

register() {
    let emailAddress = this.emailAddress
    let password = this.password
    let firstName = this.firstName
    let lastName = this.lastName
    let errorMessage = ""

    errorMessage = auth().createUserWithEmailAndPassword(emailAddress, password).then(
      function(data) {
        console.log(data)
    },function(error) {
      let errorCode = error.code
      console.log(error.message);
      let errorMessage = ""
      console.log(errorCode)
      switch(errorCode) {
        case "auth/email-already-in-use":
          console.log("auth/email-already-in-use");
          errorMessage="The email address is already in use by another account"
          break;

        case "auth/weak-password":
          console.log("auth/weak-password")
          errorMessage="Your password should be more complex"
          break;
      }
      this.displayErrorMessage(errorMessage)
    });
    console.log(errorMessage)
  }

  displayErrorMessage(errorMessage: string) {
    this.errorMessage = errorMessage;
  }

The call this.displayErrorMessage(errorMessage) is obviously not working but I don't know how to access this function properly from inside this lambda function.

The 'errorMessage' is bound to a label in the HTML via data binding. So my problem is how to pass the errorMessage from inside the lambda function to the variable 'errorMessage' outside the lambda?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Jan Kreischer
  • 679
  • 3
  • 8
  • 21

0 Answers0