5
votes

I'm using Firebase web SDK 4.0.0 and want to enable my users to verify multiple email addresses for the same account. For context, my objective is to receive email from [email protected] and [email protected] and know that it's definitely coming from Dave (uid 123456789).

I've looked up the docs about linking accounts but I'm assuming this approach isn't going to work as I need multiple emails.

I thought about storing the emails in the db and linking them to the user but that doesn't hook into the Firebase verification process (which I want to use).

Any ideas of how to approach this would be very helpful.

1
I got some idea on how to do this. It is impossible to link multiple emails in firebase authentication. However, you can user firebase database to link between those emails but why would you want a user have multiple emails?UmarZaii
@UmarZaii my app receives email so I want to allow users to send email from multiple email accounts and have them attributed to the same Firebase user account.James
What do you you mean by send email from multiple accounts?UmarZaii
@UmarZaii users send email TO my app. Many people have multiple email addresses, for example one for work and one for personal stuff. I want to acknowledge that fact and allow users to link as many email addresses as they like.James

1 Answers

4
votes

If you want a user have multiple emails registered in his account. You have to do the linking in the firebase database. Below is how to implement the structure in the database.

{
  "userAuth": {
    "userId001": {
      "userRNGId": "abc123",
      "userEmail": "[email protected]"
    },
    "userId002": {
      "userRNGId": "abc123",
      "userEmail": "[email protected]"
    }
  },

  "userList": {
    "abc123": {
      "userName": "James",
      "occupation": "Programmer",
      "userAccounts": {
        "userId001": {
          "userAuth": "userId001"
        },
        "userId002": {
          "userAuth": "userId002"
        }
      }
    }
  }
}

With this structure you can still use firebase authentication to verify their email address.

userId001 and userId002 is the RNG created from firebase authentication.

Inside userRNGId(E.g abc123) you should create random user ID so that all the emails will be linked to that id.

I hope it helps.