【问题标题】:Firebase authentication still throws error in console, even if I catch itFirebase 身份验证仍然会在控制台中引发错误,即使我发现了它
【发布时间】:2021-09-16 23:20:00
【问题描述】:

我正在尝试使用 Angular 和 Firebase 身份验证构建应用。

auth.service.ts

async loginWithEmailAndPassword(email: string, password: string) {
  try {
    await this.auth.signInWithEmailAndPassword(email, password);
  } catch(error) {
    throw error;
  }    
}

login-page.component

async loginWithEmailAndPassword() {
  if (this.form.status !== 'INVALID') {
    try {
      await this.authService.loginWithEmailAndPassword(this.email?.value, this.password?.value)
    } catch(error) {
      console.log('Hello, this is my custom error');
    }
  }
}

但在控制台中,firebase 仍然会抛出错误:

这是预期的行为吗?我认为 try...catch 可以防止这种情况发生。

我什至尝试删除异步等待语法,但没有任何改变。

【问题讨论】:

    标签: angular error-handling firebase-authentication


    【解决方案1】:

    我使用以下代码来捕获组件中的错误

    登录页面组件

       this.auth.SignIn(this.email, this.password).then(function(result){
     console.log(result);
    }).catch(function(e){
    console.log(e);
    });
    

    身份验证服务

       return this.afAuth.auth.signInWithEmailAndPassword(email, password);
    

    【讨论】:

      猜你喜欢
      • 2022-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-27
      • 2019-04-01
      • 1970-01-01
      • 2022-01-08
      • 2020-12-22
      相关资源
      最近更新 更多