feat: delete user
This commit is contained in:
parent
32127ae804
commit
7e6325d359
2 changed files with 30 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ import { Body, Controller, Delete, Get, Path, Post, Put, Route, Security, Tags }
|
||||||
import {
|
import {
|
||||||
addUserRoles,
|
addUserRoles,
|
||||||
createUser,
|
createUser,
|
||||||
|
deleteUser,
|
||||||
editUser,
|
editUser,
|
||||||
getRoles,
|
getRoles,
|
||||||
removeUserRoles,
|
removeUserRoles,
|
||||||
|
|
@ -30,6 +31,11 @@ export class KeycloakController extends Controller {
|
||||||
return await editUser(userId, body);
|
return await editUser(userId, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Delete("user/{userId}")
|
||||||
|
async deleteUser(@Path() userId: string) {
|
||||||
|
return await deleteUser(userId);
|
||||||
|
}
|
||||||
|
|
||||||
@Get("role")
|
@Get("role")
|
||||||
async getRole() {
|
async getRole() {
|
||||||
const role = await getRoles();
|
const role = await getRoles();
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ export async function createUser(username: string, password: string, opts?: Reco
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update keycloak user by given username and password with roles
|
* Update keycloak user by uuid
|
||||||
*
|
*
|
||||||
* Client must have permission to manage realm's user
|
* Client must have permission to manage realm's user
|
||||||
*
|
*
|
||||||
|
|
@ -125,6 +125,29 @@ export async function editUser(userId: string, opts: Record<string, any>) {
|
||||||
return id || true;
|
return id || true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete 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 deleteUser(userId: string) {
|
||||||
|
const res = await fetch(`${KC_URL}/admin/realms/${KC_REALM}/users/${userId}`, {
|
||||||
|
// prettier-ignore
|
||||||
|
headers: {
|
||||||
|
"authorization": `Bearer ${await getToken()}`,
|
||||||
|
"content-type": `application/json`,
|
||||||
|
},
|
||||||
|
method: "DELETE",
|
||||||
|
}).catch((e) => console.log("Keycloak Error: ", e));
|
||||||
|
|
||||||
|
if (!res) return false;
|
||||||
|
if (!res.ok) {
|
||||||
|
return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get roles list or specific role data
|
* Get roles list or specific role data
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue