From 8b9ec31deebdd06f2c05a77ccfd7dc71ecea8a34 Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Fri, 17 Apr 2026 20:26:28 +0200 Subject: [PATCH] fix(api): handle 401 responses by redirecting to login --- frontend/lib/api.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/lib/api.ts b/frontend/lib/api.ts index 2d2e286b..1d7ff37e 100644 --- a/frontend/lib/api.ts +++ b/frontend/lib/api.ts @@ -1,3 +1,4 @@ +import { redirect } from 'next/navigation'; import { getAuthHeaders } from './auth-headers'; const API_BASE = @@ -23,6 +24,9 @@ export async function fetchJson(path: string, init?: RequestInit): Promise }); if (!res.ok) { + if (res.status === 401 && isServer) { + redirect('/login'); + } const text = await res.text(); throw new Error(`API ${res.status}: ${text}`); }