// /composables/useApi.ts
export const useApi = () => {
  return $fetch.create({
    baseURL: '/api',
    credentials: 'include',
    onRequest({ request, options }) {
      // Log request
      console.log('Fetching ', request, options);
    },
    onResponseError({ response }) {
      if (response.status === 401) {
        return; // Ignore 401 unauthorized errors, they are handled by the caller.
      }
      // Log all other errors
      console.error('Fetch error ', response.status, response._data);
    },
  });
};
