feat: implement user management features including user deletion and role-based access

This commit is contained in:
2025-07-23 14:55:21 +02:00
parent 584473ba41
commit 4fed3d96f6
10 changed files with 248 additions and 86 deletions

View File

@@ -10,3 +10,38 @@ export const logout = () => {
localStorage.removeItem("users");
window.location.reload();
};
export const deleteUser = (id: number) => {
fetch("http://localhost:5002/api/deleteUser", {
method: "POST",
body: JSON.stringify({ id: id }),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${Cookies.get("token")}`,
},
})
.then((response) => {
if (response.ok) {
localStorage.removeItem("users");
document.location.reload();
} else {
alert("Failed to delete user");
}
})
.catch((error) => {
console.log("Error deleting user: ", error);
});
};
export const fetchUsers = async () => {
fetch("http://localhost:5002/api/getAllUsers", {
method: "GET",
headers: {
Authorization: `Bearer ${Cookies.get("token")}`,
},
})
.then((res) => res.json())
.then((users) => {
localStorage.setItem("users", JSON.stringify(users));
});
};