Firebase在React Native中重置密码而不使用电子邮件

huangapple go评论71阅读模式
英文:

Firebase reset password without email in React Native

问题

你好,我明白你的需求,以下是翻译好的部分:

"Hi to all community fellows out there...
I am using firebase as a backend for my React Native app. At registration time, i am asking the user to provide their phone number and email along with other required details and that information is stored in a collection. For some purpose, i decided not to use email for user authentication but made my own 'type' of email with phone number which looks like phonenumber@domain.com(03658965280@gmail.com)

Everything was working as expected, until i came across the Password Reset feature. On password reset screen, If i ask the user to enter their phone number and using that phone number, get that user's email from collection. Now I've got the user's email that i can use with following code to send the password reset link.

forgotPassword = (Email) => {
firebase.auth().sendPasswordResetEmail(Email)
.then(function (user) {
alert('Please check your email...')
}).catch(function (e) {
console.log(e)
})
}
Now I suspect that it wont send the password reset email as I have made my own version of email and when the email given to above function will be taken to firebase for cross checking, it wont be able to verify that email is correct and hence resulting in not sending the email.

Please guide me in this regard and do let me know if i am thinking in the wrong way!"

希望这对你有所帮助。

英文:

Hi to all community fellows out there...
I am using firebase as a backend for my React Native app. At registration time, i am asking the user to provide their phone number and email along with other required details and that information is stored in a collection. For some purpose, i decided not to use email for user authentication but made my own "type" of email with phone number which looks like phonenumber@domain.com(03658965280@gmail.com)

Everything was working as expected, until i came across the Password Reset feature. On password reset screen, If i ask the user to enter their phone number and using that phone number, get that user's email from collection. Now I've got the user's email that i can use with following code to send the password reset link.

forgotPassword = (Email) => {
    firebase.auth().sendPasswordResetEmail(Email)
      .then(function (user) {
        alert('Please check your email...')
      }).catch(function (e) {
        console.log(e)
      })
  }

Now I suspect that it wont send the password reset email as I have made my own version of email and when the email given to above function will be taken to firebase for cross checking, it wont be able to verify that email is correct and hence resulting in not sending the email.

Please guide me in this regard and do let me know if i am thinking in the wrong way!

答案1

得分: 1

由于您创建了一个无效的(或不存在的)电子邮件地址,内置的电子邮件验证和密码重置选项确实无法为您工作。

我可以考虑的几个主要选项是:

  1. 将电子邮件地址和电话号码分开存储。这实际上是最佳解决方案,因为它清理了无效的数据。如果用户需要能够使用电话号码或电子邮件+密码登录,您可以同时注册它们,然后将这些帐户链接在一起
  2. 实施自己的密码重置电子邮件发送,以便您可以拆分电子邮件。您仍然可以使用 Firebase 的验证处理程序通过使用 Admin SDK 生成链接,然后使用您自己的电子邮件发送脚本(和 SMTP 服务器)发送它。
  3. 以有效的格式存储电子邮件+电话号码。例如,这个电子邮件地址username+03658965280@domain.com实际上是username@domain.com的有效别名。因此,在这种格式中,您可以将电话号码存储在电子邮件地址中,仍然可以使用内置的密码重置和电子邮件验证。
英文:

Since you've created an invalid (or non-existing) email address, the built-in email verification and password reset options will indeed not work for you.

A few main options that I can think of:

  1. Store the email address and phone number separately. This honestly is the best solution, as it cleans up the invalid data. If the user needs to be able to sign in with either phone number or email+password, you can sign them up with both providers, and then link this accounts together.
  2. Implement your own password reset email sending, so that you can split the email. You can still use Firebase's verification handler by generating the link with the Admin SDK, but then sending it with your own email sending script (and SMTP server).
  3. Store the emails+phone numbers in a format that is valid. For example, this email address username+03658965280@domain.com is actually a valid alias for username@domain.com. So in this format you can store the phone number in the email address, and still use the built-in password reset and email verification.

huangapple
  • 本文由 发表于 2020年1月3日 21:48:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579713.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定