llm-router / apps /web /src /api /client.ts
ClaraSu's picture
Upload folder using huggingface_hub
e481638 verified
Raw History Blame Contribute Delete
549 Bytes
import { getToken, clearToken } from '@/lib/auth'
export async function apiFetch(path: string, options: RequestInit = {}): Promise<Response> {
const token = getToken()
const res = await fetch(path, {
cache: 'no-store',
...options,
headers: {
'Content-Type': 'application/json',
...(token ? { Authorization: `Bearer ${token}` } : {}),
...(options.headers as Record<string, string> | undefined ?? {}),
},
})
if (res.status === 401) {
clearToken()
window.location.href = '/login'
}
return res
}