deleteUsers method

Future<DeleteUsersResult> deleteUsers(
  1. List<String> uids
)
inherited

Deletes the users specified by the given uids.

Deleting a non-existing user won't generate an error (i.e. this method is idempotent.) Non-existing users are considered to be successfully deleted, and are therefore counted in the DeleteUsersResult.successCount value.

Only a maximum of 1000 identifiers may be supplied. If more than 1000 identifiers are supplied, this method throws a FirebaseAuthError.

This API is currently rate limited at the server to 1 QPS. If you exceed this, you may get a quota exceeded error. Therefore, if you want to delete more than 1000 users, you may need to add a delay to ensure you don't go over this limit.

Returns a Futrue that resolves to the total number of successful/failed deletions, as well as the array of errors that corresponds to the failed deletions.

Implementation

Future<DeleteUsersResult> deleteUsers(List<String> uids) async {
  uids.forEach(assertIsUid);

  final response =
      await _authRequestHandler.deleteAccounts(uids, force: true);
  final errors = response.errors ??
      <auth1.GoogleCloudIdentitytoolkitV1BatchDeleteErrorInfo>[];

  return DeleteUsersResult._(
    successCount: uids.length - errors.length,
    failureCount: errors.length,
    errors: errors.map((batchDeleteErrorInfo) {
      final index = batchDeleteErrorInfo.index;
      if (index == null) {
        throw FirebaseAuthAdminException(
          AuthClientErrorCode.internalError,
          'Corrupt BatchDeleteAccountsResponse detected',
        );
      }

      FirebaseAuthAdminException errMsgToError(String? msg) {
        // We unconditionally set force=true, so the 'NOT_DISABLED' error
        // should not be possible.
        final code = msg != null && msg.startsWith('NOT_DISABLED')
            ? AuthClientErrorCode.userNotDisabled
            : AuthClientErrorCode.internalError;

        return FirebaseAuthAdminException(code, batchDeleteErrorInfo.message);
      }

      return FirebaseArrayIndexError(
        index: index,
        error: errMsgToError(batchDeleteErrorInfo.message),
      );
    }).toList(),
  );
}