/** * Composable for making authenticated API calls to the Glibredecision backend. * * Uses the runtime config `apiBase` and automatically injects the Bearer token * from the auth store when available. */ export function useApi() { const config = useRuntimeConfig() const auth = useAuthStore() /** * Perform a typed fetch against the backend API. * * @param path - API path relative to apiBase, e.g. "/documents" * @param options - $fetch options (method, body, query, headers, etc.) * @returns Typed response */ async function $api(path: string, options: Record = {}): Promise { const headers: Record = {} if (auth.token) { headers.Authorization = `Bearer ${auth.token}` } return await $fetch(`${config.public.apiBase}${path}`, { ...options, headers: { ...headers, ...options.headers }, }) } return { $api } }