phase 3 initial completion

This commit is contained in:
2026-05-07 00:22:45 +02:00
parent 5d8662595c
commit ce2aa2c776
19 changed files with 1216 additions and 37 deletions
+12 -4
View File
@@ -2,12 +2,20 @@ import { z } from 'zod'
let csrfToken: string | null = null
// Called once on app bootstrap. Fetches the CSRF token and sets the cookie.
export async function bootstrapCSRF(): Promise<void> {
const res = await fetch('/api/v1/csrf', { credentials: 'include' })
if (!res.ok) return
const data = await res.json()
if (typeof data.token === 'string') {
csrfToken = data.token
}
}
async function getCSRFToken(): Promise<string> {
if (csrfToken) return csrfToken
const res = await fetch('/api/v1/csrf', { credentials: 'include' })
if (!res.ok) throw new Error('Failed to fetch CSRF token')
csrfToken = res.headers.get('X-CSRF-Token') ?? ''
return csrfToken
await bootstrapCSRF()
return csrfToken ?? ''
}
export class ApiError extends Error {