import { cookies } from 'next/headers'; import { SiteHeaderClient } from './site-header-client'; export async function SiteHeader() { const cookieStore = await cookies(); const token = cookieStore.get('motorsignal_access_token')?.value; const isProduction = process.env.NODE_ENV === 'production' && process.env.NEXT_PUBLIC_APP_ENV === 'production'; const opsToken = isProduction ? cookieStore.get('__Host-motorsignal_ops')?.value : cookieStore.get('__Host-motorsignal_ops')?.value ?? cookieStore.get('motorsignal_ops')?.value; let signedIn = false; let role = 'user'; const baseUrl = process.env.MOTORSIGNAL_API_BASE_URL ?? 'https://api.motorsignal.app'; if (token) { try { const response = await fetch(`${baseUrl}/api/v1/me`, { headers: { authorization: `Bearer ${token}` }, cache: 'no-store', }); signedIn = response.ok; if (response.ok) { role = ((await response.json()) as { role?: string }).role ?? 'user'; } } catch { /* Navigation remains available during an API outage. */ } } if (opsToken && (role === 'user' || !signedIn)) { try { const opsRes = await fetch(`${baseUrl}/api/v1/ops/me`, { headers: { authorization: `Bearer ${opsToken}` }, cache: 'no-store', }); if (opsRes.ok) { const opsData = (await opsRes.json()) as { role?: string }; role = opsData.role ?? 'operator'; signedIn = true; } } catch { /* Navigation remains available during an API outage. */ } } return ; }