Skip to content

Commit

Permalink
fix: little oopsie
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm committed Oct 9, 2024
1 parent 139fde7 commit fc9772c
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions packages/frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ import { createStore, get, set } from "idb-keyval";
export const apiStore = createStore("auth", "access");

export const createApiClientWithUrl = (url: string) => {
return createApiClient((method, url, parameters) => {
const { body, query, header } = parameters || {};

return ofetch(url, {
method,
body: body as any,
query,
headers: { ...header, Authorization: ref.token ? `Bearer ${ref.token}` : undefined } as Record<string, string>,
});
}, url);
try {
const api = createApiClient((method, url, parameters) => {
const { body, query, header } = parameters || {};

return ofetch(url, {
method,
body: body as any,
query,
headers: { ...header, Authorization: ref.token ? `Bearer ${ref.token}` : undefined } as Record<string, string>,
});
}, url);

return api;
} catch (e) {
console.error("error creating api client", e);
return null;
}
};

export const api = createApiClientWithUrl(ENV.VITE_BACKEND_URL);
Expand Down

0 comments on commit fc9772c

Please sign in to comment.