Skip to content

Provide FlowParameters for linking credentials to authenticated users #1823

@tynn

Description

@tynn

The SignInIntentBuilder.enableAnonymousUsersAutoUpgrade() provides a configuration for linking credentials to an anonymous user. It would be nice to utilize this implementation to link credentials to authenticated users as well. This is especially useful for adding a phone number to an existing users or vise versa.

This might relate to #309.

Steps to reproduce:

  1. Start AuthUI with two providers (e.g. Google and Phone)
  2. Sign in with Google
  3. Repeat 1.
  4. Sign in with Phone

Observed Results:

  • A new user was created with the phone number provided in 4.

Expected Results:

  • The phone number was added to the user signed in in 2.

Relevant Code:

From AuthOperationManager.java

public Task<AuthResult> signInAndLinkWithCredential(@NonNull FirebaseAuth auth,
                                                    @NonNull FlowParameters flowParameters,
                                                    @NonNull AuthCredential credential) {
    if (canUpgradeAnonymous(auth, flowParameters)) {
        return auth.getCurrentUser().linkWithCredential(credential);
    } else {
        return auth.signInWithCredential(credential);
    }
}

public boolean canUpgradeAnonymous(FirebaseAuth auth, FlowParameters flowParameters) {
    return flowParameters.isAnonymousUpgradeEnabled() && auth.getCurrentUser() != null &&
            auth.getCurrentUser().isAnonymous();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions