use of com.google.firebase.auth.FirebaseAuthUserCollisionException in project FirebaseUI-Android by firebase.
the class GenericIdpSignInHandler method handleNormalSignInFlow.
protected void handleNormalSignInFlow(final FirebaseAuth auth, final HelperActivityBase activity, final OAuthProvider provider) {
final boolean useEmulator = activity.getAuthUI().isUseEmulator();
auth.startActivityForSignInWithProvider(activity, provider).addOnSuccessListener(authResult -> handleSuccess(useEmulator, provider.getProviderId(), authResult.getUser(), (OAuthCredential) authResult.getCredential(), authResult.getAdditionalUserInfo().isNewUser())).addOnFailureListener(e -> {
if (e instanceof FirebaseAuthException) {
FirebaseAuthError error = FirebaseAuthError.fromException((FirebaseAuthException) e);
if (e instanceof FirebaseAuthUserCollisionException) {
FirebaseAuthUserCollisionException collisionException = (FirebaseAuthUserCollisionException) e;
setResult(Resource.forFailure(new FirebaseUiUserCollisionException(ErrorCodes.ERROR_GENERIC_IDP_RECOVERABLE_ERROR, "Recoverable error.", provider.getProviderId(), collisionException.getEmail(), collisionException.getUpdatedCredential())));
} else if (error == FirebaseAuthError.ERROR_WEB_CONTEXT_CANCELED) {
setResult(Resource.forFailure(new UserCancellationException()));
} else {
setResult(Resource.forFailure(e));
}
} else {
setResult(Resource.forFailure(e));
}
});
}
use of com.google.firebase.auth.FirebaseAuthUserCollisionException in project FirebaseUI-Android by firebase.
the class EmailLinkSignInHandler method handleNormalFlow.
private void handleNormalFlow(final AuthOperationManager authOperationManager, final EmailLinkPersistenceManager persistenceManager, final String email, final String link) {
final AuthCredential emailLinkCredential = EmailAuthProvider.getCredentialWithLink(email, link);
// Bug in core SDK - credential is mutated and won't be usable for sign in, so create
// a new one to pass back. b/117425827
final AuthCredential emailLinkCredentialForLinking = EmailAuthProvider.getCredentialWithLink(email, link);
// Either regular sign in or anonymous user upgrade
authOperationManager.signInAndLinkWithCredential(getAuth(), getArguments(), emailLinkCredential).addOnSuccessListener(authResult -> {
persistenceManager.clearAllData(getApplication());
FirebaseUser user = authResult.getUser();
IdpResponse response = new IdpResponse.Builder(new User.Builder(EMAIL_LINK_PROVIDER, user.getEmail()).setName(user.getDisplayName()).setPhotoUri(user.getPhotoUrl()).build()).build();
handleSuccess(response, authResult);
}).addOnFailureListener(e -> {
persistenceManager.clearAllData(getApplication());
if (e instanceof FirebaseAuthUserCollisionException) {
handleMergeFailure(emailLinkCredentialForLinking);
} else {
setResult(Resource.forFailure(e));
}
});
}
Aggregations