更改密码后,Angular / Firebase重定向到“登录”页面吗?

时间:2020-09-04 08:27:54

标签: angular firebase angularfire

您好,我正在使用Angular和Firebase进行身份验证。我有一个简短的问题

在成功重置密码后,有人知道如何使提示重定向到登录页面吗?

  • 我有一个忘记密码的页面,然后询问电子邮件
  • 然后将链接发送到电子邮件,电子邮件将要求用户输入新密码

上面提到的两个已成功配置,但是在成功更改密码后,我很难解决如何实现重定向到登录页面

The page only stays here after the password change

Authservice.ts密码重置方法

  resetPassword(email: string) {
    return this.afAuth.sendPasswordResetEmail(email)
      .catch(error => throw error); 
  }

Forgotpassword-component.ts

async resetPassword() {
    this.clearMessages();
    this.isClicked = true;
    this.actionButtonLabel = "Please wait...";
    await this.authService.resetPassword(this.userName).then(() => {
      this.actionButtonLabel = "Reset Password";
      this.alert.code = '200';
      this.alert.message = "A password reset link has been sent to your email address.";
      this.alert.status = 'success';
    }).catch(err => {
      this.isClicked = false;
      this.actionButtonLabel = "Reset Password";
      this.alert.code = err.code;
      this.alert.message = FirebaseErrors.Parse(err.code);
      this.alert.status = 'failed';
    })

1 个答案:

答案 0 :(得分:0)

您只需要将URL传递给sendPasswordResetEmail()函数,如下所示:

 resetPassword(email: string) {
    return this.afAuth.sendPasswordResetEmail(email, {url: "http://example.com/login"}); 
  }

也不要返回承诺并尝试同时捕获它,您应该允许任何调用resetPassword()处理错误的人。

文档: https://firebase.google.com/docs/auth/web/passing-state-in-email-actions#passing_statecontinue_url_in_email_actions

或者,您可以创建自己的着陆页,以便拥有更多控制权: https://firebase.google.com/docs/auth/custom-email-handler