diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index b349e6b3..9e152c41 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -209,7 +209,7 @@ export class KeycloakController extends Controller { @Get("user") async getUserList(@Query() first = "", @Query() max = "", @Query() search = "") { - const total = await getUserCount(); + const total = await getUserCount(first, max, search); const result = await getUserList(first, max, search); if (Array.isArray(result)) { diff --git a/src/keycloak/index.ts b/src/keycloak/index.ts index 07a531cc..b32eaf6e 100644 --- a/src/keycloak/index.ts +++ b/src/keycloak/index.ts @@ -150,13 +150,16 @@ export async function getUserList(first = "", max = "", search = "") { })); } -export async function getUserCount() { - const res = await fetch(`${KC_URL}/admin/realms/${KC_REALM}/users/count`, { - headers: { - authorization: `Bearer ${await getToken()}`, - "content-type": `application/json`, +export async function getUserCount(first = "", max = "", search = "") { + const res = await fetch( + `${KC_URL}/admin/realms/${KC_REALM}/users/count?first=${first || "0"}&max=${max || "-1"}${search ? `&search=${search}` : ""}`, + { + headers: { + authorization: `Bearer ${await getToken()}`, + "content-type": `application/json`, + }, }, - }).catch((e) => console.log("Keycloak Error: ", e)); + ).catch((e) => console.log("Keycloak Error: ", e)); if (!res) return false; if (!res.ok) {