diff --git a/src/lib/api/server/base.ts b/src/lib/api/server/base.ts index 0b8101e..359d14a 100644 --- a/src/lib/api/server/base.ts +++ b/src/lib/api/server/base.ts @@ -1,3 +1,6 @@ +import { logout } from '@/lib/auth/server'; +import { redirect } from 'next/navigation'; + const BASE_URL = process.env.API_BASE_URL || 'http://localhost:8080'; export async function fetchServerAPI( @@ -18,6 +21,10 @@ export async function fetchServerAPI( }); if (!response.ok) { + if (response.status == 401) { + await logout(); + redirect('/login'); + } throw new Error( `API Error: ${response.statusText} - ${method} - ${BASE_URL}${endpoint} - ${token}` );