no message

This commit is contained in:
kittapath 2025-02-21 11:49:04 +07:00
parent 6c67e490ae
commit c5e0fcc4f7
4 changed files with 54 additions and 1 deletions

View file

@ -736,3 +736,28 @@ export async function removeUserGroup(userId: string, groupId: string) {
return true;
}
// Function to change user password
export async function changeUserPassword(userId: string, newPassword: string) {
try {
console.log(await getToken());
const res = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users/${userId}/reset-password`, {
// prettier-ignore
headers: {
"authorization": `Bearer ${await getToken()}`,
"content-type": `application/json`,
},
method: "PUT",
body: JSON.stringify({
type: "password",
value: newPassword,
temporary: false, // Set to true if the user must reset their password on next login
}),
}).catch((e) => console.log("Keycloak Error: ", e));
return true;
} catch (error) {
console.error("Error changing password:", error);
return false;
}
}