aboutsummaryrefslogtreecommitdiffstats
path: root/web/composables/api.ts
blob: 7881afffba22302626176b8061a8c15461a5b940 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
export function $api<T>(
  request: Parameters<typeof $fetch<T>>[0],
  opts?: Parameters<typeof $fetch<T>>[1],
) {
  const authStore = useAuthStore()

  return $fetch<T>(request, {
    ...opts,
    headers: {
      Authorization: authStore.isLoggedIn() ? `Bearer ${authStore.token}` : '',
      ...opts?.headers,
    },
  })
}