Skip to content

Commit

Permalink
Fix bad sign out/delete behavior (#1240)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern authored Apr 11, 2018
2 parents 9d954e4 + a6b646b commit 032df2b
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,32 +276,36 @@ public static int getDefaultTheme() {
*/
@NonNull
public Task<Void> signOut(@NonNull Context context) {
mAuth.signOut();

Task<Void> maybeDisableAutoSignIn = GoogleApiUtils.getCredentialsClient(context)
.disableAutoSignIn()
.continueWithTask(new Continuation<Void, Task<Void>>() {
.continueWith(new Continuation<Void, Void>() {
@Override
public Task<Void> then(@NonNull Task<Void> task) {
public Void then(@NonNull Task<Void> task) {
// We want to ignore a specific exception, since it's not a good reason
// to fail (see Issue 1156).
if (!task.isSuccessful() && (task.getException() instanceof ApiException)) {
ApiException ae = (ApiException) task.getException();
if (ae.getStatusCode() == CommonStatusCodes.CANCELED) {
Log.w(TAG, "Could not disable auto-sign in, maybe there are no " +
"SmartLock accounts available?", ae);

return Tasks.forResult(null);
}
Exception e = task.getException();
if (e instanceof ApiException
&& ((ApiException) e).getStatusCode() == CommonStatusCodes.CANCELED) {
Log.w(TAG, "Could not disable auto-sign in, maybe there are no " +
"SmartLock accounts available?", e);
return null;
}

return task;
return task.getResult();
}
});

return Tasks.whenAll(
signOutIdps(context),
maybeDisableAutoSignIn);
maybeDisableAutoSignIn
).continueWith(new Continuation<Void, Void>() {
@Override
public Void then(@NonNull Task<Void> task) {
task.getResult(); // Propagate exceptions
mAuth.signOut();
return null;
}
});
}

/**
Expand All @@ -326,12 +330,6 @@ public Task<Void> delete(@NonNull Context context) {

// Ensure the order in which tasks are executed properly destructures the user.
return signOutIdps(context).continueWithTask(new Continuation<Void, Task<Void>>() {
@Override
public Task<Void> then(@NonNull Task<Void> task) {
task.getResult(); // Propagate exception if there was one
return currentUser.delete();
}
}).continueWithTask(new Continuation<Void, Task<Void>>() {
@Override
public Task<Void> then(@NonNull Task<Void> task) {
task.getResult(); // Propagate exception if there was one
Expand All @@ -341,9 +339,9 @@ public Task<Void> then(@NonNull Task<Void> task) {
credentialTasks.add(client.delete(credential));
}
return Tasks.whenAll(credentialTasks)
.continueWithTask(new Continuation<Void, Task<Void>>() {
.continueWith(new Continuation<Void, Void>() {
@Override
public Task<Void> then(@NonNull Task<Void> task) {
public Void then(@NonNull Task<Void> task) {
Exception e = task.getException();
Throwable t = e == null ? null : e.getCause();
if (!(t instanceof ApiException)
Expand All @@ -352,13 +350,19 @@ public Task<Void> then(@NonNull Task<Void> task) {
// one. This can occur if we failed to save the credential or it
// was deleted elsewhere. However, a lack of stored credential
// doesn't mean fully deleting the user failed.
task.getResult();
return task.getResult();
}

return Tasks.forResult(null);
return null;
}
});
}
}).continueWithTask(new Continuation<Void, Task<Void>>() {
@Override
public Task<Void> then(@NonNull Task<Void> task) {
task.getResult(); // Propagate exception if there was one
return currentUser.delete();
}
});
}

Expand Down

0 comments on commit 032df2b

Please sign in to comment.