extraction func is added

This commit is contained in:
2025-05-22 20:46:55 +05:30
parent f53919a3cd
commit d6d040c9e4
21 changed files with 2575 additions and 1752 deletions

View File

@@ -16,14 +16,18 @@ export async function apiRequest(
): Promise<Response> {
const token = localStorage.getItem("token");
const isFormData = typeof FormData !== "undefined" && data instanceof FormData;
const headers: Record<string, string> = {
...(token ? { Authorization: `Bearer ${token}` } : {}),
// Only set Content-Type if not using FormData
...(isFormData ? {} : { "Content-Type": "application/json" }),
};
const res = await fetch(`${API_BASE_URL}${url}`, {
method,
// headers: data ? { "Content-Type": "application/json" } : {},
headers: {
"Content-Type": "application/json",
...(token ? { Authorization: `Bearer ${token}` } : {}), // Include JWT token if available
},
body: data ? JSON.stringify(data) : undefined,
headers,
body: isFormData ? data as FormData : JSON.stringify(data),
credentials: "include",
});