export default defineNuxtPlugin(() => {
  const { cookieConfig } = useRuntimeConfig().public;

  const api = $fetch.create({
    baseURL: "/",
    retry: 1,
    retryStatusCodes: [401],
    retryDelay: 500,
    onRequest({ options }) {
      const sid = useCookie("sid", cookieConfig).value ?? "";
      options.headers.set("Authorization", sid);
    },
  });

  // Expose to useNuxtApp().$api
  return {
    provide: {
      api,
    },
  };
});
