fix
This commit is contained in:
parent
6e5f20ed18
commit
055173a038
4 changed files with 57 additions and 3 deletions
|
|
@ -203,6 +203,45 @@ export async function editUser(userId: string, opts: Record<string, any>) {
|
|||
const id = path?.split("/").at(-1);
|
||||
return id || true;
|
||||
}
|
||||
/**
|
||||
* Update keycloak user by uuid
|
||||
*
|
||||
* Client must have permission to manage realm's user
|
||||
*
|
||||
* @returns user uuid or true if success, false otherwise.
|
||||
*/
|
||||
export async function updateName(
|
||||
userId: string,
|
||||
firstName: string,
|
||||
lastName: string,
|
||||
opts: Record<string, any>,
|
||||
) {
|
||||
const { password, ...rest } = opts;
|
||||
|
||||
const res = await fetch(`${KC_URL}/admin/realms/${KC_REALM}/users/${userId}`, {
|
||||
// prettier-ignore
|
||||
headers: {
|
||||
"authorization": `Bearer ${await getToken()}`,
|
||||
"content-type": `application/json`,
|
||||
},
|
||||
method: "PUT",
|
||||
body: JSON.stringify({
|
||||
enabled: true,
|
||||
credentials: (password && [{ type: "password", value: opts?.password }]) || undefined,
|
||||
...rest,
|
||||
}),
|
||||
}).catch((e) => console.log("Keycloak Error: ", e));
|
||||
|
||||
if (!res) return false;
|
||||
if (!res.ok) {
|
||||
// return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
const path = res.headers.get("Location");
|
||||
const id = path?.split("/").at(-1);
|
||||
return id || true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete keycloak user by uuid
|
||||
|
|
@ -588,4 +627,6 @@ export async function removeUserGroup(userId: string, groupId: string) {
|
|||
}
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue