Skip to content

Commit a6b646b

Browse files
committed
Fix bad sign out/delete behavior
Signed-off-by: Alex Saveau <[email protected]>
1 parent 9d954e4 commit a6b646b

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

auth/src/main/java/com/firebase/ui/auth/AuthUI.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -276,32 +276,36 @@ public static int getDefaultTheme() {
276276
*/
277277
@NonNull
278278
public Task<Void> signOut(@NonNull Context context) {
279-
mAuth.signOut();
280-
281279
Task<Void> maybeDisableAutoSignIn = GoogleApiUtils.getCredentialsClient(context)
282280
.disableAutoSignIn()
283-
.continueWithTask(new Continuation<Void, Task<Void>>() {
281+
.continueWith(new Continuation<Void, Void>() {
284282
@Override
285-
public Task<Void> then(@NonNull Task<Void> task) {
283+
public Void then(@NonNull Task<Void> task) {
286284
// We want to ignore a specific exception, since it's not a good reason
287285
// to fail (see Issue 1156).
288-
if (!task.isSuccessful() && (task.getException() instanceof ApiException)) {
289-
ApiException ae = (ApiException) task.getException();
290-
if (ae.getStatusCode() == CommonStatusCodes.CANCELED) {
291-
Log.w(TAG, "Could not disable auto-sign in, maybe there are no " +
292-
"SmartLock accounts available?", ae);
293-
294-
return Tasks.forResult(null);
295-
}
286+
Exception e = task.getException();
287+
if (e instanceof ApiException
288+
&& ((ApiException) e).getStatusCode() == CommonStatusCodes.CANCELED) {
289+
Log.w(TAG, "Could not disable auto-sign in, maybe there are no " +
290+
"SmartLock accounts available?", e);
291+
return null;
296292
}
297293

298-
return task;
294+
return task.getResult();
299295
}
300296
});
301297

302298
return Tasks.whenAll(
303299
signOutIdps(context),
304-
maybeDisableAutoSignIn);
300+
maybeDisableAutoSignIn
301+
).continueWith(new Continuation<Void, Void>() {
302+
@Override
303+
public Void then(@NonNull Task<Void> task) {
304+
task.getResult(); // Propagate exceptions
305+
mAuth.signOut();
306+
return null;
307+
}
308+
});
305309
}
306310

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

327331
// Ensure the order in which tasks are executed properly destructures the user.
328332
return signOutIdps(context).continueWithTask(new Continuation<Void, Task<Void>>() {
329-
@Override
330-
public Task<Void> then(@NonNull Task<Void> task) {
331-
task.getResult(); // Propagate exception if there was one
332-
return currentUser.delete();
333-
}
334-
}).continueWithTask(new Continuation<Void, Task<Void>>() {
335333
@Override
336334
public Task<Void> then(@NonNull Task<Void> task) {
337335
task.getResult(); // Propagate exception if there was one
@@ -341,9 +339,9 @@ public Task<Void> then(@NonNull Task<Void> task) {
341339
credentialTasks.add(client.delete(credential));
342340
}
343341
return Tasks.whenAll(credentialTasks)
344-
.continueWithTask(new Continuation<Void, Task<Void>>() {
342+
.continueWith(new Continuation<Void, Void>() {
345343
@Override
346-
public Task<Void> then(@NonNull Task<Void> task) {
344+
public Void then(@NonNull Task<Void> task) {
347345
Exception e = task.getException();
348346
Throwable t = e == null ? null : e.getCause();
349347
if (!(t instanceof ApiException)
@@ -352,13 +350,19 @@ public Task<Void> then(@NonNull Task<Void> task) {
352350
// one. This can occur if we failed to save the credential or it
353351
// was deleted elsewhere. However, a lack of stored credential
354352
// doesn't mean fully deleting the user failed.
355-
task.getResult();
353+
return task.getResult();
356354
}
357355

358-
return Tasks.forResult(null);
356+
return null;
359357
}
360358
});
361359
}
360+
}).continueWithTask(new Continuation<Void, Task<Void>>() {
361+
@Override
362+
public Task<Void> then(@NonNull Task<Void> task) {
363+
task.getResult(); // Propagate exception if there was one
364+
return currentUser.delete();
365+
}
362366
});
363367
}
364368

0 commit comments

Comments
 (0)