diff --git a/auth/src/main/java/com/firebase/ui/auth/AuthUI.java b/auth/src/main/java/com/firebase/ui/auth/AuthUI.java index d1ed18737..c77831c8a 100644 --- a/auth/src/main/java/com/firebase/ui/auth/AuthUI.java +++ b/auth/src/main/java/com/firebase/ui/auth/AuthUI.java @@ -276,32 +276,36 @@ public static int getDefaultTheme() { */ @NonNull public Task signOut(@NonNull Context context) { - mAuth.signOut(); - Task maybeDisableAutoSignIn = GoogleApiUtils.getCredentialsClient(context) .disableAutoSignIn() - .continueWithTask(new Continuation>() { + .continueWith(new Continuation() { @Override - public Task then(@NonNull Task task) { + public Void then(@NonNull Task 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() { + @Override + public Void then(@NonNull Task task) { + task.getResult(); // Propagate exceptions + mAuth.signOut(); + return null; + } + }); } /** @@ -326,12 +330,6 @@ public Task delete(@NonNull Context context) { // Ensure the order in which tasks are executed properly destructures the user. return signOutIdps(context).continueWithTask(new Continuation>() { - @Override - public Task then(@NonNull Task task) { - task.getResult(); // Propagate exception if there was one - return currentUser.delete(); - } - }).continueWithTask(new Continuation>() { @Override public Task then(@NonNull Task task) { task.getResult(); // Propagate exception if there was one @@ -341,9 +339,9 @@ public Task then(@NonNull Task task) { credentialTasks.add(client.delete(credential)); } return Tasks.whenAll(credentialTasks) - .continueWithTask(new Continuation>() { + .continueWith(new Continuation() { @Override - public Task then(@NonNull Task task) { + public Void then(@NonNull Task task) { Exception e = task.getException(); Throwable t = e == null ? null : e.getCause(); if (!(t instanceof ApiException) @@ -352,13 +350,19 @@ public Task then(@NonNull Task 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>() { + @Override + public Task then(@NonNull Task task) { + task.getResult(); // Propagate exception if there was one + return currentUser.delete(); + } }); }