feat: keycloak user and role management
This commit is contained in:
parent
bee7c0bfa5
commit
7a291fb3be
2 changed files with 56 additions and 5 deletions
|
|
@ -121,7 +121,7 @@ export async function getRoles(name?: string) {
|
|||
const data = await res.json();
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
return data.map((v: Record<string, any>) => ({ id: v.id, name: v.name }));
|
||||
return data.map((v: Record<string, string>) => ({ id: v.id, name: v.name }));
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
@ -137,7 +137,7 @@ export async function getRoles(name?: string) {
|
|||
*
|
||||
* @returns true if success, false otherwise.
|
||||
*/
|
||||
export async function addUserRoles(userId: string, roleId: string[]) {
|
||||
export async function addUserRoles(userId: string, roles: { id: string; name: string }[]) {
|
||||
const res = await fetch(
|
||||
`${KC_URL}/admin/realms/${KC_REALM}/users/${userId}/role-mappings/realm`,
|
||||
{
|
||||
|
|
@ -147,7 +147,7 @@ export async function addUserRoles(userId: string, roleId: string[]) {
|
|||
"content-type": `application/json`,
|
||||
},
|
||||
method: "POST",
|
||||
body: JSON.stringify(roleId.map((v) => ({ id: v }))),
|
||||
body: JSON.stringify(roles),
|
||||
},
|
||||
).catch((e) => console.log(e));
|
||||
|
||||
|
|
@ -165,7 +165,7 @@ export async function addUserRoles(userId: string, roleId: string[]) {
|
|||
*
|
||||
* @returns true if success, false otherwise.
|
||||
*/
|
||||
export async function removeUserRoles(userId: string, roleId: string[]) {
|
||||
export async function removeUserRoles(userId: string, roles: { id: string; name: string }[]) {
|
||||
const res = await fetch(
|
||||
`${KC_URL}/admin/realms/${KC_REALM}/users/${userId}/role-mappings/realm`,
|
||||
{
|
||||
|
|
@ -175,7 +175,7 @@ export async function removeUserRoles(userId: string, roleId: string[]) {
|
|||
"content-type": `application/json`,
|
||||
},
|
||||
method: "DELETE",
|
||||
body: JSON.stringify(roleId.map((v) => ({ id: v }))),
|
||||
body: JSON.stringify(roles),
|
||||
},
|
||||
).catch((e) => console.log(e));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue