即使身份验证不成功也会更改页面

Page changing even with unsuccessful auth

我这里有一个简单的方法,它尝试登录用户,如果成功,会将用户路由到 ProfileSetupPage。

async onLogin(user: User){
    try {
      const result = this.afAuth.auth.signInWithEmailAndPassword(user.email, user.password);
      if (result){
        this.navCtrl.setRoot(ProfileSetupPage);
      }
    }catch (e){
      console.error(e);
    }
  }

如果我尝试登录,我会收到运行时错误消息 'there is no user record corresponding to this identifier. The user may have been deleted',这很好,但是当我关闭此消息时 - 用户仍被重定向到 ProfileSetupPage。既然结果明显是假的,那为什么还要执行this.navCtrl.setRoot方法呢?

新手 angular/ionic 此处是编码器 - 对此提供帮助将不胜感激!另外,如果不成功而不是运行时错误覆盖,有没有办法显示消息?谢谢!!

它返回一个 Promise

你应该这样做

并根据其抛出错误的文档添加 catch

async onLogin(user: User){
    const result = this.afAuth.auth.signInWithEmailAndPassword(user.email, user.password)
    .then((res) =>{
     this.navCtrl.setRoot(ProfileSetupPage);
    })
    .catch((error) =>{  console.error(error);});
}