Plateforme de decisions collectives pour Duniter/G1. Backend FastAPI async + PostgreSQL (14 tables, 8 routers, 6 services, moteur de vote avec formule d'inertie WoT/Smith/TechComm). Frontend Nuxt 4 + Nuxt UI v3 + Pinia (9 pages, 5 stores). Infrastructure Docker + Woodpecker CI + Traefik. Documentation technique et utilisateur (15 fichiers). Seed : Licence G1, Engagement Forgeron v2.0.0, 4 protocoles de vote. 30 tests unitaires (formules, mode params, vote nuance) -- tous verts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
32 lines
925 B
TypeScript
32 lines
925 B
TypeScript
/**
|
|
* 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<T>(path: string, options: Record<string, any> = {}): Promise<T> {
|
|
const headers: Record<string, string> = {}
|
|
if (auth.token) {
|
|
headers.Authorization = `Bearer ${auth.token}`
|
|
}
|
|
|
|
return await $fetch<T>(`${config.public.apiBase}${path}`, {
|
|
...options,
|
|
headers: { ...headers, ...options.headers },
|
|
})
|
|
}
|
|
|
|
return { $api }
|
|
}
|