diff --git a/src/app/[locale]/admin/clubs/page.tsx b/src/app/[locale]/admin/clubs/page.tsx index d2dc256..d22a12e 100644 --- a/src/app/[locale]/admin/clubs/page.tsx +++ b/src/app/[locale]/admin/clubs/page.tsx @@ -3,13 +3,18 @@ import { getTranslate } from '../../dictionaries'; import { Building, AlertCircle, Lock } from 'lucide-react'; import { getAdminClubs } from '@/src/lib/api/admin-clubs'; import Link from 'next/link'; +import { cookies } from 'next/headers'; export default async function AdminClubsPage({ params }: { params: Promise<{ locale: Locale }>}) { const { locale } = await params; const {t} = await getTranslate(locale); + // Get cookies for SSR auth + const cookieStore = await cookies(); + const cookieHeader = cookieStore.toString(); + // Fetch clubs from API - this will handle auth states via HTTP status codes - const result = await getAdminClubs(); + const result = await getAdminClubs(cookieHeader); // Handle authentication error (401) if (!result.success && result.error.status === 401) { diff --git a/src/lib/api/admin-clubs.ts b/src/lib/api/admin-clubs.ts index 4d1bbb9..238a4c7 100644 --- a/src/lib/api/admin-clubs.ts +++ b/src/lib/api/admin-clubs.ts @@ -62,16 +62,24 @@ async function handleApiResponse(response: Response): Promise> { +export async function getAdminClubs(cookieHeader?: string): Promise> { try { + const headers: Record = { + 'Content-Type': 'application/json', + }; + + // Forward cookies for server-side rendering + if (cookieHeader) { + headers['Cookie'] = cookieHeader; + } + const response = await fetch(`${API_BASE_URL}/admin/clubs`, { method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - credentials: 'include', // Include cookies for auth + headers, + credentials: cookieHeader ? 'omit' : 'include', // Use 'omit' when manually setting Cookie header }); return handleApiResponse(response); @@ -95,18 +103,27 @@ export async function getAdminClubs(): Promise> { try { + const headers: Record = { + 'Content-Type': 'application/json', + }; + + // Forward cookies for server-side rendering + if (cookieHeader) { + headers['Cookie'] = cookieHeader; + } + const response = await fetch(`${API_BASE_URL}/admin/clubs/${clubId}`, { method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - credentials: 'include', // Include cookies for auth + headers, + credentials: cookieHeader ? 'omit' : 'include', // Use 'omit' when manually setting Cookie header }); return handleApiResponse(response);