import { initAuth } from '../stores/auth.ts' import { API } from '../main.ts' export async function apiFetch( path: string, options: RequestInit = {} ): Promise { const auth = await initAuth() const res = await fetch(`${API}${path}`, { ...options, headers: { 'Content-Type': 'application/json', ...(auth.token ? { Authorization: `Bearer ${auth.token}` } : {}), ...options.headers, }, }) if (!res.ok) { const text = await res.text() throw new Error(text || res.statusText) } return res.json() }