【问题标题】:AngularFire2 Authentication Error: First argument "email" must be a valid stringAngularFire2 身份验证错误:第一个参数“电子邮件”必须是有效字符串
【发布时间】:2016-10-18 21:47:02
【问题描述】:

我正在尝试使用 angularFire2 和 Firebase 为我的网络应用制作登录和注册表单。

在获取用户注册信息并将其传递到 signInWithEmailAndPassword 函数时出现错误。

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

我的组件中有处理作为字符串类型的电子邮件变量的所有内容,并且它作为字符串记录到控制台,所以我不确定到底发生了什么。

我已经研究了将近 3 个小时,但找不到任何可以解决问题的方法。

模板:

<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)

【问题讨论】:

  • 您可以发布您尝试登录的电子邮件吗?可能是无效的。
  • 这是我自己的个人邮箱,并且是有效的邮箱。
  • 你有没有在登录功能中尝试console.log(email,password)`?
  • 我也尝试过其他电子邮件地址。即使是我拥有但不是我的主要帐户的其他帐户,我也会遇到同样的错误。
  • 是的,我正在控制台中取回电子邮件和密码。

标签: angular firebase firebase-authentication angularfire angularfire2


【解决方案1】:

af.auth.login() 的签名是一个具有两个属性的对象:

// 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()。

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

【讨论】:

  • 是的!你是对的大声笑。完全错过了那里的物体!谢谢!
猜你喜欢
  • 2021-02-08
  • 2021-02-10
  • 2018-03-23
  • 2018-03-04
  • 2020-09-24
  • 1970-01-01
  • 2019-02-26
  • 2018-08-29
  • 1970-01-01
相关资源
最近更新 更多