listUsers method

Future<List<User>> listUsers({
  1. int? page,
  2. int? perPage,
})

Get a list of users.

This function should only be called on a server. Never expose your service_role key on the client.

The result is paginated. Use the page and perPage parameters to paginate the result.

Implementation

Future<List<User>> listUsers({int? page, int? perPage}) async {
  final options = GotrueRequestOptions(
    headers: _headers,
    query: {
      if (page != null) 'page': page.toString(),
      if (perPage != null) 'per_page': perPage.toString(),
    },
  );
  final response = await _fetch.request(
    '$_url/admin/users',
    RequestMethodType.get,
    options: options,
  );
  return (response['users'] as List).map((e) => User.fromJson(e)!).toList();
}