Link Multiple Auth Providers to an Account using C++

You can allow users to sign in to your app using multiple authentication
providers by linking auth provider credentials to an existing user account.
Users are identifiable by the same Firebase user ID regardless of the
authentication provider they used to sign in. For example, a user who signed in
with a password can link a Google account and sign in with either method in the
future. Or, an anonymous user can link a Facebook account and then, later, sign
in with Facebook to continue using your app.

Before you begin

Add support for two or more authentication providers (possibly including
anonymous authentication) to your app.

Link auth provider credentials to a user account

To link auth provider credentials to an existing user account:

Sign in the user using any authentication provider or method.

Complete the sign-in flow for the new authentication provider up to, but not
including, calling one of the firebase::auth::Auth::SignInWithCredential methods. For example, get
the user's Google ID token, Facebook access token, or email and password.

Pass the firebase::auth::Credential object to the signed-in user's
LinkWithCredential method:

// Link the new credential to the currently active user.
firebase::auth::User* current_user = auth->current_user();
firebase::Future<firebase::auth::User*> result =
current_user->LinkWithCredential(credential);

The call to LinkWithCredential will fail if the credentials are
already linked to another user account. In this situation, you must handle
merging the accounts and associated data as appropriate for your app: