Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle user backing out of social flows #1764

Merged
merged 2 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.data.model.Resource;
import com.firebase.ui.auth.data.model.User;
import com.firebase.ui.auth.data.model.UserCancellationException;
import com.firebase.ui.auth.ui.HelperActivityBase;
import com.firebase.ui.auth.util.ExtraConstants;
import com.firebase.ui.auth.viewmodel.ProviderSignInBase;
Expand Down Expand Up @@ -111,7 +112,7 @@ public void onSuccess(LoginResult result) {

@Override
public void onCancel() {
onError(new FacebookException());
setResult(Resource.<IdpResponse>forFailure(new UserCancellationException()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.firebase.ui.auth.data.model.UserCancellationException;
import com.firebase.ui.auth.ui.HelperActivityBase;
import com.firebase.ui.auth.util.ExtraConstants;
import com.firebase.ui.auth.util.FirebaseAuthError;
import com.firebase.ui.auth.util.data.AuthOperationManager;
import com.firebase.ui.auth.util.data.ProviderUtils;
import com.firebase.ui.auth.viewmodel.ProviderSignInBase;
Expand All @@ -32,6 +33,7 @@
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthException;
import com.google.firebase.auth.FirebaseAuthUserCollisionException;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.OAuthCredential;
Expand Down Expand Up @@ -91,17 +93,27 @@ public void onSuccess(@NonNull AuthResult authResult) {
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if (e instanceof FirebaseAuthUserCollisionException) {
FirebaseAuthUserCollisionException collisionException =
(FirebaseAuthUserCollisionException) e;

setResult(Resource.<IdpResponse>forFailure(
new FirebaseUiUserCollisionException(
ErrorCodes.ERROR_GENERIC_IDP_RECOVERABLE_ERROR,
"Recoverable error.",
provider.getProviderId(),
collisionException.getEmail(),
collisionException.getUpdatedCredential())));
if (e instanceof FirebaseAuthException) {
FirebaseAuthError error =
FirebaseAuthError.fromException((FirebaseAuthException) e);

if (e instanceof FirebaseAuthUserCollisionException) {
FirebaseAuthUserCollisionException collisionException =
(FirebaseAuthUserCollisionException) e;

setResult(Resource.<IdpResponse>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.<IdpResponse>forFailure(
new UserCancellationException()));
} else {
setResult(Resource.<IdpResponse>forFailure(e));
}
} else {
setResult(Resource.<IdpResponse>forFailure(e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.firebase.auth.FirebaseAuthException;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;

/**
Expand Down Expand Up @@ -83,6 +84,8 @@ public enum FirebaseAuthError {

ERROR_API_NOT_AVAILABLE("The API that you are calling is not available on devices without Google Play Services."),

ERROR_WEB_CONTEXT_CANCELED("The web operation was canceled by the user"),

ERROR_UNKNOWN("An unknown error occurred.");

/**
Expand Down