AngularFire2 Authentication Error: First argument “email” must be a valid string

最后都变了- 提交于 2020-02-23 04:36:28

问题


I am trying to make login and signup forms for my web app using angularFire2 and Firebase.

I am getting an error when taking a users signup information and passing it into the signInWithEmailAndPassword function.

signInWithEmailAndPassword failed: First argument "email" must be a valid string.

I have everything in my component that deals with the email variable typed as a string and it logs to the console as a string so I am not sure exactly what is going on.

I have researched for almost 3 hours now and cant find anything that could fix the issue.

Template:

<form action="" class="login">
   <input type="email" name="loginEmail" id="loginEmail" placeholder="email" [(ngModel)]="signInEmail">
   <input type="password" name="loginPassword" id="loginPassword" placeholder="password" [(ngModel)]="signInPassword">
    <a href="#">Forgot Password?</a>
    <button type="submit" (click)="login(signInEmail, signInPassword)">Sign In</button>
</form>

Component:

// Sign In
  signInEmail: string;
  signInPassword: string;

  constructor(private _songsService: SongService, private _router: Router, public af: AngularFire) {
    this.backgroundImage = '../images/main-bg.jpg';
    this.logoIcon = '../images/logo-icon.png';
  }

  login(email, password) {
    console.log('login');
    this.af.auth.login( email, password );
  }

NgModule

const firebaseAuthConfig = {
  provider: AuthProviders.Password,
  method: AuthMethods.Password
}

@NgModule({
  imports: [
    BrowserModule,
    routing,
    HttpModule,
    JsonpModule,
    FormsModule,
    AngularFireModule.initializeApp(firebaseConfig, firebaseAuthConfig)

回答1:


The signature for af.auth.login() is one object with two properties:

// Email and password
af.auth.login({
  email: 'email@example.com',
  password: 'password',
},
{
  provider: AuthProviders.Password,
  method: AuthMethods.Password,
})

https://github.com/angular/angularfire2/blob/master/docs/5-user-authentication.md

... if you're using username and password, then you'll have to call af.auth.login() with the user's credentials.

af.auth.login({ email: 'email', password: 'pass' });



来源:https://stackoverflow.com/questions/40118652/angularfire2-authentication-error-first-argument-email-must-be-a-valid-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!