This commit is contained in:
talorr
2026-03-27 03:36:08 +03:00
parent 8a97ce6d54
commit cda36918e8
225 changed files with 35641 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
export function useChatApi<T>(path: string, options: Parameters<typeof $fetch<T>>[1] = {}) {
const config = useRuntimeConfig();
const { token, user } = useAuth();
const headers = new Headers(options.headers as HeadersInit | undefined);
if (!headers.has("Content-Type") && options.method && options.method !== "GET") {
headers.set("Content-Type", "application/json");
}
if (token.value) {
headers.set("Authorization", `Bearer ${token.value}`);
}
if (user.value?.email) {
headers.set("x-user-email", user.value.email);
}
return $fetch<T>(`${config.public.chatApiBase}${path}`, {
...options,
headers,
credentials: "include"
}).catch((error: Error) => {
throw new Error(error.message || "Не удалось выполнить запрос к чату");
});
}