Skip to content

Fix bad sign out/delete behavior #1240

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

Merged
merged 1 commit into from
Apr 11, 2018
Merged
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
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