diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 3ae9074..fa93d10 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -4,6 +4,10 @@ const BASE = '/twin-optimiser/api' async function request(path: string, opts?: RequestInit): Promise { const res = await fetch(BASE + path, { credentials: 'include', ...opts }) + if (res.status === 401) { + ;(window.top ?? window).location.href = '/login' + throw new Error('Unauthenticated') + } if (!res.ok) { const body = await res.json().catch(() => ({})) as { error?: string } throw new Error(body.error || `HTTP ${res.status}`)