getUsers method

Future<GetUsersResult> getUsers(
  1. List<UserIdentifier> identifiers
)
inherited

Gets the user data corresponding to the specified identifiers.

There are no ordering guarantees; in particular, the nth entry in the result list is not guaranteed to correspond to the nth entry in the input parameters list.

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

Takes a list of UserIdentifier used to indicate which user records should be returned. Must not have more than 100 entries.

Returns a Future that resolves to the corresponding user records. Throws FirebaseAdminException if any of the identifiers are invalid or if more than 100 identifiers are specified.

Implementation

Future<GetUsersResult> getUsers(List<UserIdentifier> identifiers) async {
  final response =
      await _authRequestHandler.getAccountInfoByIdentifiers(identifiers);

  final userRecords = response.users?.map(UserRecord.fromResponse).toList() ??
      const <UserRecord>[];

  // Checks if the specified identifier is within the list of UserRecords.
  bool isUserFound(UserIdentifier id) {
    return userRecords.any((userRecord) {
      switch (id) {
        case UidIdentifier():
          return id.uid == userRecord.uid;
        case EmailIdentifier():
          return id.email == userRecord.email;
        case PhoneIdentifier():
          return id.phoneNumber == userRecord.phoneNumber;
        case ProviderIdentifier():
          final matchingUserInfo = userRecord.providerData
              .firstWhereOrNull((userInfo) => userInfo.phoneNumber != null);
          return matchingUserInfo != null &&
              id.providerUid == matchingUserInfo.uid;
      }
    });
  }

  final notFound = identifiers.where((id) => !isUserFound(id)).toList();

  return GetUsersResult._(users: userRecords, notFound: notFound);
}