fix update prefix and profileId
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m45s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m45s
This commit is contained in:
parent
e4f46a1762
commit
2951630b7b
10 changed files with 201 additions and 69 deletions
|
|
@ -298,6 +298,7 @@ export async function updateName(
|
|||
userId: string,
|
||||
firstName: string,
|
||||
lastName: string,
|
||||
prefix: string,
|
||||
// opts: Record<string, any>,
|
||||
) {
|
||||
// const { password, ...rest } = opts;
|
||||
|
|
@ -315,6 +316,9 @@ export async function updateName(
|
|||
// ...rest,
|
||||
firstName,
|
||||
lastName,
|
||||
attributes: {
|
||||
prefix,
|
||||
},
|
||||
}),
|
||||
}).catch((e) => console.log("Keycloak Error: ", e));
|
||||
|
||||
|
|
@ -971,3 +975,44 @@ export async function getAllUsersPaginated(
|
|||
enabled: v.enabled === true || v.enabled === "true",
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create keycloak user by given username and password with roles
|
||||
*
|
||||
* Client must have permission to manage realm's user
|
||||
*
|
||||
* @returns user uuid or true if success, false otherwise.
|
||||
*/
|
||||
export async function createUserHaveProfile(
|
||||
username: string,
|
||||
password: string,
|
||||
profileId: string,
|
||||
prefix: string,
|
||||
opts?: Record<string, any>,
|
||||
token?: string,
|
||||
) {
|
||||
const res = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users`, {
|
||||
// prettier-ignore
|
||||
headers: {
|
||||
"authorization": `Bearer ${token || await getToken()}`,
|
||||
"content-type": `application/json`,
|
||||
},
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
enabled: true,
|
||||
credentials: [{ type: "password", value: password, temporary: false }],
|
||||
username,
|
||||
...opts,
|
||||
}),
|
||||
}).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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue