MCPcopy Create free account
hub / github.com/ForgeAILab/forge / authFetch

Function authFetch

web/src/api/auth.ts:8–30  ·  view source on GitHub ↗
(path: string, init?: RequestInit)

Source from the content-addressed store, hash-verified

6} from '@/types/generated'
7
8async function authFetch<T>(path: string, init?: RequestInit): Promise<T> {
9 const response = await fetch(`/api/v1${path}`, {
10 ...init,
11 headers: {
12 'content-type': 'application/json',
13 ...(init?.headers as Record<string, string> | undefined),
14 },
15 })
16 if (!response.ok) {
17 const text = await response.text()
18 let message = response.statusText
19 try {
20 const json = JSON.parse(text) as { message?: string }
21 if (json.message) message = json.message
22 } catch {
23 if (text) message = text
24 }
25 throw new Error(message)
26 }
27 const text = await response.text()
28 if (response.status === 204 || text.length === 0) return undefined as T
29 return JSON.parse(text) as T
30}
31
32export function register(body: RegisterRequest): Promise<AuthResponse> {
33 return authFetch<AuthResponse>('/auth/register', {

Callers 4

registerFunction · 0.85
loginFunction · 0.85
logoutApiFunction · 0.85
getMeFunction · 0.85

Calls 2

fetchFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected