Firebase: signInWithEmailAndPassword failed: Second argument "password" must be a valid string

0

I'mgettingareturnnullformysecondparameternexttothesignInWithEmailAndPasswordmethod.Thiserrorinhibitedmyauthentication.

publicautenticar(email:string,senha:string):void{firebase.auth().signInWithEmailAndPassword(email,senha).then((resposta:any)=>{firebase.auth().currentUser.getIdToken().then((idToken:string)=>{this.token_id=idTokenlocalStorage.setItem('idToken',idToken)this.router.navigate(['/home'])})}).catch((error:Error)=>console.log(error))}

TemplateCode:

<form[formGroup]="formulario" (ngSubmit)="autenticar()">
  <div class="form-group">
    <input
      type="email"
      class="form-control"
      placeholder="E-mail"
      formControlName="email"
    >
  </div>
  <div class="form-group">
    <input
      type="password"
      class="form-control"
      placeholder="Senha"
      formGroupName="senha"
    >
  </div>
  <button type="submit" class="btn btn-primary btn-sm btn-block">Entrar</button>
</form>
    
asked by anonymous 22.12.2018 / 03:06

1 answer

1

The error was occurring because in the app template the formControlName for the "password" field, was set to formGroupName="password" being that the correct would be formControlName="password", this was due to an oversight with self- complete It is worth learning to always check the structure of the reactive-form in the template to avoid this type of error.

 <div class="form-group">
    <input
      type="password"
      class="form-control"
      placeholder="Senha"
      formControlName="senha">
  </div>

Details about Reactive Forms in the official documentation of the Angular.

    
26.12.2018 / 02:43