(url, options = {})
| 10 | } |
| 11 | |
| 12 | async function apiFetch(url, options = {}) { |
| 13 | const method = (options.method || 'GET').toUpperCase() |
| 14 | |
| 15 | const headers = new Headers(options.headers || {}) |
| 16 | |
| 17 | if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(method)) { |
| 18 | const token = await ensureCSRF() |
| 19 | headers.set('X-CSRF-Token', token) |
| 20 | } |
| 21 | |
| 22 | return fetch(url, { |
| 23 | credentials: 'include', |
| 24 | ...options, |
| 25 | headers, |
| 26 | }) |
| 27 | } |
| 28 | |
| 29 | export async function checkAuth() { |
| 30 | const res = await fetch('/api/ui/auth/status', { credentials: 'include' }) |
no test coverage detected