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:
@@ -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)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user