AngularFire2身份验证错误:第一个参数“电子邮件"必须是有效的字符串 [英] AngularFire2 Authentication Error: First argument "email" must be a valid string

查看:168
本文介绍了AngularFire2身份验证错误:第一个参数“电子邮件"必须是有效的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用angularFire2和Firebase为我的Web应用程序创建登录和注册表单.

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 failed: First argument "email" must be a valid string.

我组件中的所有内容都与字符串形式的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 );
  }

NgModule

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',密码:'pass'});

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

这篇关于AngularFire2身份验证错误:第一个参数“电子邮件"必须是有效的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆