Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase verify multiple email addresses for the same user

Tags:

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.

like image 559
James Avatar asked Jul 17 '17 16:07

James


People also ask

Is Firebase user UID unique?

Firebase users have a fixed set of basic properties—a unique ID, a primary email address, a name and a photo URL—stored in the project's user database, that can be updated by the user (iOS, Android, web).

Can I create a user with the same credentials in Firebase?

Firebase account linking allows users to sign into the same account using different authentication providers. By linking the user's Facebook and Twitter credentials, for example, the user can sign into the same account using either sign-in provider.

How do I verify my email on Firebase authentication?

Enable Email Link sign-in for your Firebase projectIn the Firebase console, open the Auth section. On the Sign in method tab, enable the Email/Password provider. Note that email/password sign-in must be enabled to use email link sign-in. In the same section, enable Email link (passwordless sign-in) sign-in method.


1 Answers

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.

like image 180
UmarZaii Avatar answered Oct 11 '22 13:10

UmarZaii