Skip to content

Commit

Permalink
fix: headers cannot be set (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: TinsFox <[email protected]>
  • Loading branch information
nmsbnmsb1 and TinsFox authored Sep 20, 2024
1 parent f9eb573 commit 16b804e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib/api-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 16b804e

Please sign in to comment.