import { paths } from './schema.ts' import createClient, { Client, Middleware } from 'openapi-fetch' import { dispatchMessage } from '../messageBus/messageBus.ts' export type ApiClient = Client export function initClient(): ApiClient { const client = createClient({ baseUrl: import.meta.env.VITE_API_URL }) const UnauthorizedHandlerMiddleware: Middleware = { async onResponse({ response }) { console.debug('on response middleware?') console.debug(response.headers.getSetCookie()) console.debug(response.headers.get('set-cookie')) if (response.status === 401) { dispatchMessage('auth:unauthorized', null) } }, } client.use(UnauthorizedHandlerMiddleware) return client }