edtech / apps /web /src /lib /api.ts
CognxSafeTrack
fix(audit): resolve 15 critical and major technical debt issues
97f541f
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:3001';
const ORG_ID = import.meta.env.VITE_ORG_ID as string | undefined;
export async function apiRequest<T = any>(endpoint: string, options: RequestInit = {}): Promise<T> {
const orgHeaders: Record<string, string> = ORG_ID ? { 'x-organization-id': ORG_ID } : {};
const res = await fetch(`${API_URL}${endpoint}`, {
...options,
headers: {
'Content-Type': 'application/json',
...orgHeaders,
...options.headers,
},
});
if (!res.ok) {
const errorData = await res.json().catch(() => ({}));
const error = new Error(errorData.error || 'Une erreur est survenue');
(error as any).status = res.status;
throw error;
}
return res.json();
}
export const apiClient = {
getStudent: (phone: string) => apiRequest(`/v1/student/me?phone=${phone}`),
// Future endpoints can be added here
};