use of com.google.android.gms.auth.api.credentials.CredentialsClient in project FirebaseUI-Android by firebase.
the class AuthUI method delete.
/**
* Delete the use from FirebaseAuth and delete any associated credentials from the Credentials
* API. Returns a {@link Task} that succeeds if the Firebase Auth user deletion succeeds and
* fails if the Firebase Auth deletion fails. Credentials deletion failures are handled
* silently.
*
* @param context the calling {@link Context}.
*/
@NonNull
public Task<Void> delete(@NonNull final Context context) {
final FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser == null) {
return Tasks.forException(new FirebaseAuthInvalidUserException(String.valueOf(CommonStatusCodes.SIGN_IN_REQUIRED), "No currently signed in user."));
}
final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
// Ensure the order in which tasks are executed properly destructures the user.
return signOutIdps(context).continueWithTask(task -> {
// Propagate exception if there was one
task.getResult();
if (!GoogleApiUtils.isPlayServicesAvailable(context)) {
Log.w(TAG, "Google Play services not available during delete");
return Tasks.forResult((Void) null);
}
final CredentialsClient client = GoogleApiUtils.getCredentialsClient(context);
List<Task<?>> credentialTasks = new ArrayList<>();
for (Credential credential : credentials) {
credentialTasks.add(client.delete(credential));
}
return Tasks.whenAll(credentialTasks).continueWith(task1 -> {
Exception e = task1.getException();
Throwable t = e == null ? null : e.getCause();
if (!(t instanceof ApiException) || ((ApiException) t).getStatusCode() != CommonStatusCodes.CANCELED) {
// doesn't mean fully deleting the user failed.
return task1.getResult();
}
return null;
});
}).continueWithTask(task -> {
// Propagate exception if there was one
task.getResult();
return currentUser.delete();
});
}
Aggregations