0
votes

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 [email protected]([email protected])

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 Answers

1
votes

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 [email protected] is actually a valid alias for [email protected]. 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.