自定义firebase“电子邮件验证”密码重置“密码”页面

发布于 2025-02-13 04:41:33 字数 903 浏览 0 评论 0 原文

我在Angular应用程序(带有Angular-Fire)中使用Firebase和Firestore Auth,效果很好。 对于功能“密码忘记”和“电子邮件验证”,我确实在 angularFireauth 服务上调用这些方法:

  sendVerificationMail() {
    return this.afAuth.currentUser
      .then((u: any) => u.sendEmailVerification())
      .then(() => {
        this.router.navigate(['/', 'auth', 'verify-email']);
      });
  }
  async forgotPassword(passwordResetEmail: string) {
    try {
      await this.afAuth.sendPasswordResetEmail(passwordResetEmail);
      window.alert('Password reset email sent, check your inbox.');
    } catch (error) {
      window.alert(error);
    }
  }

它有效,我收到电子邮件以验证我的电子邮件或重置我的密码,但是:

  1. 它们是 : URL喜欢 https://xxxx.firebaseapp.com ,而不是我的自定义域
  2. 一旦设置了新密码,或者只是单击了电子邮件验证链接,我无法重定向他们到主页上​​的
  3. 页面与我的Angular应用程序的设计不同。

我的问题是,我可以为某些自定义页面提供URL吗?还是自定义设计?还是一些重定向动作?将某些内容更好地集成到我的网站上?

I'm using Firebase and Firestore auth in an angular application(with angular-fire), which works nicely.
For the feature "password forgotten" and "email validation", I do call those methods on the AngularFireAuth service:

  sendVerificationMail() {
    return this.afAuth.currentUser
      .then((u: any) => u.sendEmailVerification())
      .then(() => {
        this.router.navigate(['/', 'auth', 'verify-email']);
      });
  }
  async forgotPassword(passwordResetEmail: string) {
    try {
      await this.afAuth.sendPasswordResetEmail(passwordResetEmail);
      window.alert('Password reset email sent, check your inbox.');
    } catch (error) {
      window.alert(error);
    }
  }

It works, I receive email to validate my email or to reset my password, but:

  1. They are URL like https://xxxx.firebaseapp.com instead of my custom domain
  2. Once they set their new password, or just clicked on the email validation link, I cannot redirect them to the home page
  3. The page isn't with the same design as my angular app.

My question is, can I provide URL to some custom page? Or customize the design? Or some redirect action? To have something that is a bit better integrated to my website?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

-柠檬树下少年和吉他 2025-02-20 04:41:33

您可以在firebase控制台下自定义密码重置电子邮件 - > auth->电子邮件模板 - >重置密码,然后更改电子邮件中的链接,以指向您自己的页面。请注意,占位符将被URL中的密码重置代码替换。

然后,在自定义页面中,您可以从URL读取密码重置代码,并执行

firebase.auth().confirmPasswordReset(code, newPassword)
    .then(function() {
      // Success
    })
    .catch(function() {
      // Invalid code
    })

https://firebase.google.com/docs/reference/js/firebase.auth.auth.auth.auth#confirmpasswordreset https://firebase.google.com/docs/reference/js/firebase.auth.auth.auth#verifypasswordresetcode

You can customize the Password Reset email under Firebase Console -> Auth -> Email Templates -> Password Reset, and change the link in the email to point to your own page. Note that the placeholder will be replaced by the password reset code in the URL.

Then, in your custom page, you can read the password reset code from the URL and do

firebase.auth().confirmPasswordReset(code, newPassword)
    .then(function() {
      // Success
    })
    .catch(function() {
      // Invalid code
    })

https://firebase.google.com/docs/reference/js/firebase.auth.Auth#confirmPasswordReset https://firebase.google.com/docs/reference/js/firebase.auth.Auth#verifyPasswordResetCode

梦开始←不甜 2025-02-20 04:41:33

这是用于重置后重定向的重定向,您必须通过ActionCodeSettings通过持续URL将用户重定向到应用程序:

var actionCodeSettings = {
  // After password reset, the user will be give the ability to go back
  // to this page.
  url: 'https://www.example.com/afterPasswordReset',
  handleCodeInApp: false
};
firebase.auth().sendPasswordResetEmail(email, actionCodeSettings)
  .then(function() {
    // Password reset email sent.
  })
  .catch(function(error) {
    // Error occurred. Inspect error.code.
  });

了解有关ActionCodesettings并以重定向传递状态的更多信息:https://firebase.google.com/docs/auth/web/passing-state-in-email-actions

You can also build your own custom landing page here:

This is for redirect after password reset, You have to pass a continue URL via ActionCodeSettings to redirect the user back to the app:

var actionCodeSettings = {
  // After password reset, the user will be give the ability to go back
  // to this page.
  url: 'https://www.example.com/afterPasswordReset',
  handleCodeInApp: false
};
firebase.auth().sendPasswordResetEmail(email, actionCodeSettings)
  .then(function() {
    // Password reset email sent.
  })
  .catch(function(error) {
    // Error occurred. Inspect error.code.
  });

Learn more about ActionCodeSettings and passing state in redirect: https://firebase.google.com/docs/auth/web/passing-state-in-email-actions

You can also build your own custom landing page here: https://firebase.google.com/docs/auth/custom-email-handler

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文