buildAuthHeaders function

  1. @visibleForTesting
Map<String, String> buildAuthHeaders({
  1. required String apiKey,
  2. String? accessToken,
})

Split-header auth overlay, FFI-free so it can be unit-tested without a native library: apikey always travels independently of Authorization, and Authorization: Bearer carries only a JWT access token. A missing token omits the header entirely rather than falling back to the API key (matches Kotlin's HTTPClientAdapter.buildHeaders) — collapsing the two turns a missing/expired-token failure into the backend's misleading "Invalid JWT token: Not enough segments".

Implementation

@visibleForTesting
Map<String, String> buildAuthHeaders({
  required String apiKey,
  String? accessToken,
}) {
  final headers = <String, String>{};
  if (apiKey.isNotEmpty) {
    headers['apikey'] = apiKey;
  }
  if (accessToken != null && accessToken.isNotEmpty) {
    headers['Authorization'] = 'Bearer $accessToken';
  }
  return headers;
}