Paginated administration
Build an admin user-management table with pages of accounts.
Better Auth · Module
Lists users through the Better Auth admin API, with optional search, pagination, sorting, and filtering. The server-side endpoint requires authenticated session cookies.
The admin plugin exposes listUsers through the server auth API. It accepts an optional query object for searching, pagination, sorting, and filtering, and requires session cookies in the server-side example.
auth.api.listUsers({ query?, headers? })| Name | Type | Description |
|---|---|---|
query | object | Optional query options including searchValue, searchField, searchOperator, limit, offset, sortBy, sortDirection, filterField, filterValue, and filterOperator. |
headers | Headers | Request headers containing the authenticated session cookies. |
A user-list response containing users and pagination metadata such as total, limit, and offset.
const { users, total, limit, offset } = await auth.api.listUsers({
query: {
searchValue: "alice",
searchField: "email",
searchOperator: "contains",
limit: 20,
offset: 0,
sortBy: "name",
sortDirection: "asc",
filterField: "email",
filterValue: "@example.com",
filterOperator: "contains",
},
headers: await headers(),
});Calls the server API to retrieve matching users with pagination, sorting, and filtering.
Build an admin user-management table with pages of accounts.
Locate accounts by email or display name.
Order or narrow administrative results before rendering them.
It is a server-side method exposed as auth.api.listUsers. The method can query users by search value, field, and operator, while also supporting pagination, sorting, and filtering.
Follow-up: How would you avoid requesting the entire result set? Supply limit and offset, then use the returned pagination metadata to request subsequent pages.
The searchable field can be email or name. Search operators include contains, starts_with, and ends_with; filtering additionally supports operators such as eq.
Follow-up: How would you search names beginning with a prefix? Set searchField to name and searchOperator to starts_with.
The server example passes headers from the current request because the endpoint requires session cookies. This lets Better Auth identify the authenticated session when the method is called.
Follow-up: What should a caller do if it invokes the method outside a request context? Ensure authenticated request headers are explicitly available and forwarded.
authClient.admin.listUsersadmin pluginGET /admin/list-users