added auth support

This commit is contained in:
Edward Tirado Jr 2026-02-24 00:20:54 -06:00
parent 869be69d67
commit f3dbaef776
7 changed files with 112 additions and 3 deletions

17
app/composables/$api.ts Normal file
View file

@ -0,0 +1,17 @@
export const $api = <T>(
path: string,
options: Parameters<typeof $fetch<T>>[1] = {}
) => {
const config = useRuntimeConfig()
const xsrfToken = useCookie('XSRF-TOKEN')
return $fetch<T>(path, {
baseURL: config.public.apiBase,
credentials: 'include',
headers: {
Accept: 'application/json',
...(xsrfToken.value ? {'X-XSRF-TOKEN': xsrfToken.value} : {}),
},
...options,
})
}