Spaces:
Build error
Build error
PrimeStake Deployer
Fix betting features: add auth headers, Redis checks, and decimal handling
0bd1a7a Download frontend/lib/api/client.ts from Enternal1/primestake: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/Enternal1/primestake/resolve/main/frontend/lib/api/client.ts
- Command line
-
hf download hf://spaces/Enternal1/primestake/frontend/lib/api/client.ts
-
curl -L -o client.ts https://huggingface.co/spaces/Enternal1/primestake/resolve/main/frontend/lib/api/client.ts
1.17 kB
| import { useAuthStore } from "../store/useAuthStore"; | |
| const baseUrl = | |
| process.env.NEXT_PUBLIC_API_BASE_URL || "http://localhost:4000/api"; | |
| async function request(input: string, init?: RequestInit) { | |
| const token = useAuthStore.getState().token; | |
| const res = await fetch(`${baseUrl}${input}`, { | |
| ...init, | |
| headers: { | |
| "Content-Type": "application/json", | |
| ...(token ? { Authorization: `Bearer ${token}` } : {}), | |
| ...(init?.headers || {}) | |
| } | |
| }); | |
| if (!res.ok) { | |
| const text = await res.text(); | |
| throw new Error(text || "Request failed"); | |
| } | |
| return res.json(); | |
| } | |
| export const apiClient = { | |
| get: (url: string, init?: RequestInit) => | |
| request(url, { ...init, method: "GET" }), | |
| post: (url: string, body?: unknown, init?: RequestInit) => | |
| request(url, { | |
| ...init, | |
| method: "POST", | |
| body: body ? JSON.stringify(body) : undefined | |
| }), | |
| put: (url: string, body?: unknown, init?: RequestInit) => | |
| request(url, { | |
| ...init, | |
| method: "PUT", | |
| body: body ? JSON.stringify(body) : undefined | |
| }), | |
| delete: (url: string, init?: RequestInit) => | |
| request(url, { ...init, method: "DELETE" }) | |
| }; | |