Extract Auth Header logic into new function handleAuthHeaders().