feat(users): add user administration and password management

This commit is contained in:
Schubert Ferenc 2026-07-11 14:04:30 +02:00
parent 47f54d3461
commit b584e60273
16 changed files with 720 additions and 22 deletions

View file

@ -1,4 +1,4 @@
export const API_BASE = process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8000/api/v1";
export const API_BASE = process.env.NEXT_PUBLIC_API_BASE_URL ?? "/api/v1";
export type Entity = {
id: string;
@ -61,6 +61,17 @@ export type Equipment = Entity & {
status: "green" | "yellow" | "red";
};
export type User = Entity & {
email: string;
first_name: string;
last_name: string;
role: "admin" | "pruefer" | "mitarbeiter" | "leser";
is_active: boolean;
must_change_password: boolean;
last_login_at?: string | null;
password_changed_at?: string | null;
};
export type ValidationItem = Entity & {
report_number: string;
customer_id: string;
@ -154,3 +165,14 @@ export async function apiDelete(path: string, token: string): Promise<void> {
throw new Error(`API request failed: ${response.status}`);
}
}
export async function apiFetch<T>(path: string, token: string, init?: RequestInit): Promise<T> {
const response = await fetch(`${API_BASE}${path}`, {
...init,
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json", ...(init?.headers ?? {}) }
});
if (!response.ok) {
throw new Error(await response.text());
}
return response.json() as Promise<T>;
}