diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index f7c39eee..45a2b69f 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -223,7 +223,12 @@ export default function CourrierPage() { if (!isMounted) return; // Call the session API to check email credentials and start prefetching - const response = await fetch('/api/courrier/session'); + const response = await fetch('/api/courrier/session', { + credentials: 'include', // Ensure cookies are sent + headers: { + 'Content-Type': 'application/json', + } + }); // Handle 401 Unauthorized with retry logic if (response.status === 401) { @@ -234,7 +239,9 @@ export default function CourrierPage() { return initSession(); } else { console.error('Max retries reached for session request'); - throw new Error('Failed to authenticate session after multiple attempts'); + // Instead of throwing, redirect to login + router.push('/courrier/login'); + return; } }