diff --git a/front-end/app/composables/useApi.ts b/front-end/app/composables/useApi.ts new file mode 100644 index 0000000..55dba40 --- /dev/null +++ b/front-end/app/composables/useApi.ts @@ -0,0 +1,17 @@ +// Wrapper sobre $fetch que injeta o Authorization header automaticamente. +export function useApi() { + const { public: { apiBase } } = useRuntimeConfig() + const token = useCookie('auth_token') + + function apiFetch(path: string, options: Parameters[1] = {}): Promise { + return $fetch(`${apiBase}${path}`, { + ...options, + headers: { + ...(options.headers as Record || {}), + ...(token.value ? { Authorization: `Bearer ${token.value}` } : {}), + }, + }) + } + + return { apiFetch } +} diff --git a/front-end/app/pages/sistema/configuracoes.vue b/front-end/app/pages/sistema/configuracoes.vue index 592d1a1..7a40b8f 100644 --- a/front-end/app/pages/sistema/configuracoes.vue +++ b/front-end/app/pages/sistema/configuracoes.vue @@ -1,10 +1,33 @@