feat(frontend): add apiFetch wrapper for automatic auth token injection

Centralizes auth token management into a reusable apiFetch() helper and getAuthHeaders() utility, eliminating inline Bearer token logic across all frontend files.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-07-06 19:21:34 +01:00
co-authored by Sisyphus
parent e831953e5b
commit 92124158bf
48 changed files with 530 additions and 1190 deletions
@@ -1,5 +1,6 @@
<script lang="ts">
import { authStore } from '$lib/stores/auth.svelte';
import { apiFetch } from '$lib/utils/api';
import { toast } from 'svelte-sonner';
import { Button } from '$lib/components/ui/button';
import * as Card from '$lib/components/ui/card';
@@ -36,9 +37,7 @@
async function fetchSettings() {
loading = true;
try {
const res = await fetch('/api/admin/settings', {
headers: { Authorization: `Bearer ${authStore.currentToken}` }
});
const res = await apiFetch('/api/admin/settings');
if (res.ok) {
settings = await res.json();
} else {
@@ -237,11 +236,10 @@
return;
}
const res = await fetch('/api/admin/settings', {
const res = await apiFetch('/api/admin/settings', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${authStore.currentToken}`
'Content-Type': 'application/json'
},
body: JSON.stringify(patch)
});