Skip to content

Commit a57bf05

Browse files
committed
Refactor delete method
Signed-off-by: Alex Saveau <[email protected]>
1 parent 499e719 commit a57bf05

File tree

1 file changed

+8
-38
lines changed

1 file changed

+8
-38
lines changed

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

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -368,46 +368,12 @@ public Void then(@NonNull Task<GoogleApiClient> task) throws Exception {
368368
*/
369369
@Deprecated
370370
public Task<Void> delete(@NonNull Activity activity) {
371-
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
372-
if (firebaseUser == null) {
373-
// If the current user is null, return a failed task immediately
374-
return Tasks.forException(new Exception("No currently signed in user."));
375-
}
376-
377-
// Delete the Firebase user
378-
Task<Void> deleteUserTask = firebaseUser.delete();
379-
380371
// Initialize SmartLock helper
381372
GoogleApiClientTaskHelper gacHelper = GoogleApiClientTaskHelper.getInstance(activity);
382373
gacHelper.getBuilder().addApi(Auth.CREDENTIALS_API);
383374
CredentialApiHelper credentialHelper = CredentialsApiHelper.getInstance(gacHelper);
384375

385-
// Get all SmartLock credentials associated with the user
386-
List<Credential> credentials = SmartLockBase.credentialsFromFirebaseUser(firebaseUser);
387-
388-
// For each Credential in the list, create a task to delete it.
389-
List<Task<?>> credentialTasks = new ArrayList<>();
390-
for (Credential credential : credentials) {
391-
credentialTasks.add(credentialHelper.delete(credential));
392-
}
393-
394-
// Create a combined task that will succeed when all credential delete operations
395-
// have completed (even if they fail).
396-
final Task<Void> combinedCredentialTask = Tasks.whenAll(credentialTasks);
397-
398-
// Chain the Firebase Auth delete task with the combined Credentials task
399-
// and return.
400-
return deleteUserTask.continueWithTask(new Continuation<Void, Task<Void>>() {
401-
@Override
402-
public Task<Void> then(@NonNull Task<Void> task) throws Exception {
403-
// Call getResult() to propagate failure by throwing an exception
404-
// if there was one.
405-
task.getResult(Exception.class);
406-
407-
// Return the combined credential task
408-
return combinedCredentialTask;
409-
}
410-
});
376+
return getDeleteTask(credentialHelper);
411377
}
412378

413379
/**
@@ -447,6 +413,13 @@ public Task<Void> signOut(@NonNull FragmentActivity activity) {
447413
* @param activity the calling {@link Activity}.
448414
*/
449415
public Task<Void> delete(@NonNull FragmentActivity activity) {
416+
// Initialize SmartLock helper
417+
CredentialApiHelper credentialHelper = GoogleSignInHelper.getInstance(activity);
418+
419+
return getDeleteTask(credentialHelper);
420+
}
421+
422+
private Task<Void> getDeleteTask(CredentialApiHelper credentialHelper) {
450423
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
451424
if (firebaseUser == null) {
452425
// If the current user is null, return a failed task immediately
@@ -456,9 +429,6 @@ public Task<Void> delete(@NonNull FragmentActivity activity) {
456429
// Delete the Firebase user
457430
Task<Void> deleteUserTask = firebaseUser.delete();
458431

459-
// Initialize SmartLock helper
460-
GoogleSignInHelper credentialHelper = GoogleSignInHelper.getInstance(activity);
461-
462432
// Get all SmartLock credentials associated with the user
463433
List<Credential> credentials = SmartLockBase.credentialsFromFirebaseUser(firebaseUser);
464434

0 commit comments

Comments
 (0)