import { API_URL } from '@shared/config/env' import { getCsrfToken } from './csrf' async function request(path: string, options: RequestInit = {}): Promise { const token = await getCsrfToken() const res = await fetch(`${API_URL}${path}`, { ...options, credentials: 'include', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': token, ...options.headers, }, }) const data = await res.json() if (!res.ok) throw data return data as T } export const api = { get: (path: string) => request(path), post: (path: string, body: unknown) => request(path, { method: 'POST', body: JSON.stringify(body) }), }