问题
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