api enableStatus
This commit is contained in:
parent
f05c2f4b63
commit
d613637c95
2 changed files with 46 additions and 7 deletions
|
|
@ -147,6 +147,7 @@ export async function getUserList(first = "", max = "", search = "") {
|
|||
firstName: v.firstName,
|
||||
lastName: v.lastName,
|
||||
email: v.email,
|
||||
enabled: v.enabled,
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
@ -233,9 +234,7 @@ export async function updateName(
|
|||
lastName,
|
||||
}),
|
||||
}).catch((e) => console.log("Keycloak Error: ", e));
|
||||
console.log("firstName: ", firstName);
|
||||
console.log("lastName: ", lastName);
|
||||
|
||||
|
||||
if (!res) return false;
|
||||
if (!res.ok) {
|
||||
// return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
||||
|
|
@ -247,6 +246,39 @@ export async function updateName(
|
|||
return id || true;
|
||||
}
|
||||
|
||||
/**
|
||||
* enable 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 enableStatus(
|
||||
userId: string,
|
||||
status: boolean,
|
||||
) {
|
||||
|
||||
const res = await fetch(`${KC_URL}/admin/realms/${KC_REALM}/users/${userId}`, {
|
||||
headers: {
|
||||
authorization: `Bearer ${await getToken()}`,
|
||||
"content-type": `application/json`,
|
||||
},
|
||||
method: "PUT",
|
||||
body: JSON.stringify({
|
||||
enabled: status,
|
||||
}),
|
||||
}).catch((e) => console.log("Keycloak Error: ", e));
|
||||
|
||||
if (!res) return false;
|
||||
if (!res.ok) {
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
const path = res.headers.get("Location");
|
||||
const id = path?.split("/").at(-1);
|
||||
return id || true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete keycloak user by uuid
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue