Linking multiple providers to an account

This document shows you how to link multiple providers to a single Identity Platform account.

Identity Platform uses a unique ID to identify users. This allows users to sign in to the same account with different providers. For example, a user who initially registered with a phone number could later link their Google account, and then use either method to sign in.

Before you begin

Add support for two or more identity providers to your app.

Enabling or disabling account linking

The account linking setting determines how Identity Platform handles users attempting to sign in with the same email using different providers.

  • Link accounts that use the same email: Identity Platform will raise an error if a user tries to sign in with an email that's already in use. Your app can catch this error, and link the new provider to their existing account.

  • Create multiple accounts for each identity provider: A new Identity Platform user account will be created each time a user signs in with a different provider.

To choose a setting:

  1. Go to the Identity Platform Settings page in the Google Cloud console.

    Go to the Settings page

  2. Select a setting under User account linking.

  3. Click Save.

Linking federated provider credentials

To link credentials from a federated provider:

  1. Sign in the user with any authentication provider or method.

  2. Get the provider object that corresponds to the provider you want to link to the user's account. For example:

    Web version 9

    import { GoogleAuthProvider, FacebookAuthProvider, TwitterAuthProvider, GithubAuthProvider } from "firebase/auth";
    
    const googleProvider = new GoogleAuthProvider();
    const facebookProvider = new FacebookAuthProvider();
    const twitterProvider = new TwitterAuthProvider();
    const githubProvider = new GithubAuthProvider();

    Web version 8

    var googleProvider = new firebase.auth.GoogleAuthProvider();
    var facebookProvider = new firebase.auth.FacebookAuthProvider();
    var twitterProvider = new firebase.auth.TwitterAuthProvider();
    var githubProvider = new firebase.auth.