From 7a0ab2271df4e1f35d823882f2babf2d785f16ec Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 29 Jan 2025 15:31:32 +0700 Subject: [PATCH] no message --- src/keycloak/index.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/keycloak/index.ts b/src/keycloak/index.ts index 1369e307..d4f5f8a6 100644 --- a/src/keycloak/index.ts +++ b/src/keycloak/index.ts @@ -490,15 +490,18 @@ export async function getUserRoles(userId: string) { * @returns true if success, false otherwise. */ export async function addUserRoles(userId: string, roles: { id: string; name: string }[]) { - const res = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users/${userId}`, { - // prettier-ignore - headers: { + const res = await fetch( + `${KC_URL}/admin/realms/${KC_REALMS}/users/${userId}/role-mappings/realm`, + { + // prettier-ignore + headers: { "authorization": `Bearer ${await getToken()}`, "content-type": `application/json`, }, - method: "POST", - body: JSON.stringify(roles), - }).catch((e) => console.log(e)); + method: "POST", + body: JSON.stringify(roles), + }, + ).catch((e) => console.log(e)); if (!res) return false; if (!res.ok) {