diff --git a/src/lib/api-fetch.ts b/src/lib/api-fetch.ts index 931a378..2bbf365 100644 --- a/src/lib/api-fetch.ts +++ b/src/lib/api-fetch.ts @@ -3,6 +3,23 @@ import { FetchError, ofetch } from "ofetch" export const apiFetch = ofetch.create({ credentials: "include", retry: false, + onRequest: async ({ options }) => { + const header = new Headers(options.headers) + + options.headers = header + + if (options.method && options.method.toLowerCase() !== "get") { + if (typeof options.body === "string") { + options.body = JSON.parse(options.body) + } + if (!options.body) { + options.body = {} + } + } + }, + onResponse() { + // TODO: response interceptor + }, onResponseError(context) { if (context.response.status === 401) { return redirectToLogin()