Follow-up to a7609ff for the whole frontend: all 30 API helpers in
src/lib now pass path values through encodeURIComponent, so an id taken
from the URL can never leave its own path segment and make the page call
another endpoint with the viewer's token.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { apiFetch } from "@/lib/auth/api-client";
|
|
import { CreateUserInput, UpdateUserInput, User } from "./types";
|
|
|
|
export function fetchUsers(): Promise<User[]> {
|
|
return apiFetch<User[]>("/users");
|
|
}
|
|
|
|
export function createUser(input: CreateUserInput): Promise<User> {
|
|
return apiFetch<User>("/users", {
|
|
method: "POST",
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export function updateUser(id: string, input: UpdateUserInput): Promise<User> {
|
|
return apiFetch<User>(`/users/${encodeURIComponent(id)}`, {
|
|
method: "PATCH",
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export function resetUserPassword(
|
|
id: string,
|
|
password: string,
|
|
): Promise<User> {
|
|
return apiFetch<User>(`/users/${encodeURIComponent(id)}/reset-password`, {
|
|
method: "POST",
|
|
body: JSON.stringify({ password }),
|
|
});
|
|
}
|
|
|
|
export function deactivateUser(id: string): Promise<User> {
|
|
return apiFetch<User>(`/users/${encodeURIComponent(id)}/deactivate`, { method: "POST" });
|
|
}
|
|
|
|
export function activateUser(id: string): Promise<User> {
|
|
return apiFetch<User>(`/users/${encodeURIComponent(id)}/activate`, { method: "POST" });
|
|
}
|
|
|
|
export function resetUserMfa(id: string): Promise<User> {
|
|
return apiFetch<User>(`/users/${encodeURIComponent(id)}/mfa/reset`, { method: "POST" });
|
|
}
|