feat: implement API security measures phase 1

This commit is contained in:
Marko (Hermes Implementer)
2026-05-27 00:24:09 +00:00
parent a0b3ae7e34
commit c2fc7bc15f
21 changed files with 1050 additions and 44 deletions
+13 -2
View File
@@ -11,9 +11,20 @@ interface UseDashboardDataResult {
const API_BASE = "/api";
async function fetchJson<T>(url: string): Promise<T> {
const response = await fetch(url);
const token = localStorage.getItem("access_token");
const headers: Record<string, string> = {
"Content-Type": "application/json",
};
if (token) {
headers["Authorization"] = `Bearer ${token}`;
}
const response = await fetch(url, { headers });
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
const body = await response.json().catch(() => ({}));
throw new Error(
(body as { error?: string }).error ||
`HTTP ${response.status}: ${response.statusText}`
);
}
return response.json() as Promise<T>;
}