AngularFire2 身份验证错误:第一个参数“电子邮件"必须是有效字符串 [英] AngularFire2 Authentication Error: First argument "email" must be a valid string
问题描述
我正在尝试使用 angularFire2 和 Firebase 为我的网络应用制作登录和注册表单.
I am trying to make login and signup forms for my web app using angularFire2 and Firebase.
我在获取用户注册信息并将其传递给 signInWithEmailAndPassword 函数时出错.
I am getting an error when taking a users signup information and passing it into the signInWithEmailAndPassword function.
signInWithEmailAndPassword 失败:第一个参数email"必须是有效字符串.
我的组件中包含所有处理作为字符串键入的电子邮件变量的所有内容,并将其作为字符串记录到控制台,因此我不确定到底发生了什么.
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.
我已经研究了将近 3 个小时,但找不到任何可以解决问题的方法.
I have researched for almost 3 hours now and cant find anything that could fix the issue.
模板:
<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>
组件:
// 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 );
}
Ng 模块
const firebaseAuthConfig = {
provider: AuthProviders.Password,
method: AuthMethods.Password
}
@NgModule({
imports: [
BrowserModule,
routing,
HttpModule,
JsonpModule,
FormsModule,
AngularFireModule.initializeApp(firebaseConfig, firebaseAuthConfig)
推荐答案
af.auth.login()
的签名是一个具有两个属性的对象:
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
...如果您使用用户名和密码,则必须使用用户的凭据调用 af.auth.login().
... 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' });
af.auth.login({ email: 'email', password: 'pass' });
这篇关于AngularFire2 身份验证错误:第一个参数“电子邮件"必须是有效字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!