feat: integra /sistema/usuarios e /sistema/configuracoes com API real
- useApi.ts: composable centralizado com Authorization header automático - usuarios.vue: GET /api/v1/users — lista usuários reais do tenant - configuracoes.vue: GET/PUT /api/v1/tenant/me — carrega e salva dados reais Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
17
front-end/app/composables/useApi.ts
Normal file
17
front-end/app/composables/useApi.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
// Wrapper sobre $fetch que injeta o Authorization header automaticamente.
|
||||
export function useApi() {
|
||||
const { public: { apiBase } } = useRuntimeConfig()
|
||||
const token = useCookie<string | null>('auth_token')
|
||||
|
||||
function apiFetch<T>(path: string, options: Parameters<typeof $fetch>[1] = {}): Promise<T> {
|
||||
return $fetch<T>(`${apiBase}${path}`, {
|
||||
...options,
|
||||
headers: {
|
||||
...(options.headers as Record<string, string> || {}),
|
||||
...(token.value ? { Authorization: `Bearer ${token.value}` } : {}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return { apiFetch }
|
||||
}
|
||||
Reference in New Issue
Block a user