import { auth } from '../auth';

/**
 * Returnerar Authorization-header med JWT från sessionen.
 * Används i alla server-side API-proxy-routes.
 */
export async function getAuthHeaders(): Promise<Record<string, string>> {
  const session = await auth();
  // eslint-disable-next-line no-console
  console.log('[getAuthHeaders] Session data:', {
    hasSession: !!session,
    hasAccessToken: !!session?.accessToken,
    sessionKeys: session ? Object.keys(session) : [],
    userRole: (session?.user as any)?.role,
  });
  if (!session?.accessToken) {
    // eslint-disable-next-line no-console
    console.warn('[getAuthHeaders] No accessToken found! Session:', session);
    return {};
  }
  // eslint-disable-next-line no-console
  console.log('[getAuthHeaders] Returning Bearer token');
  return { Authorization: `Bearer ${session.accessToken}` };
}
