I am using Firebase Authentication in my android application. I am able to login users with their Gmail Id or phone number. I want to link phone number if the user is already signed-in with email id or vise-vers. I referred to Firebase Auth documentation for account linking but they have done it manually (getting phone number and OTP manually). But on its main page of FirebaseUI, it is written
Account Linking - flows to safely link user accounts across identity providers.
as one of its features. But it is not mentioned how to use FirebaseUI for account linking.
Here is what I have done till now:
I am using these three functions to sign in the user.
public void signInWithAllProviders() {
List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.PhoneBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build(),
new AuthUI.IdpConfig.FacebookBuilder().build());
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.build(),
RC_SIGN_IN);
}
public void signInWithPhone() {
startActivityForResult(
AuthUI.getInstance().
createSignInIntentBuilder().
setAvailableProviders(Collections.singletonList(new AuthUI.IdpConfig.PhoneBuilder().build())).
build(),
RC_PHONE_SIGN_IN);
}
public void signInWithEmail() {
startActivityForResult(
AuthUI.getInstance().
createSignInIntentBuilder().
setAvailableProviders(Arrays.asList(
new AuthUI.IdpConfig.GoogleBuilder().build(),
new AuthUI.IdpConfig.EmailBuilder().build())).
build(),
RC_EMAIL_SIGN_IN);
}
When the user is already signed in, and he tries to sign in with a phone number by calling
signInWithPhone()
, the FirebaseUI is replacing the previously signed in credentials. So I am not able to link accounts.
Am I missing anything?
FirebaseUI handles automatic account linking (when one account per email is enabled). This covers the following similar cases:
FirebaseUI will support the case above but does not support manual linking as you are trying to do, where you want to link a phone number to a signed in user. Feel free to file a feature request for it in the FirebaseUI repo.