fetchCodeMieProjects function

Future<List<String>> fetchCodeMieProjects(
  1. String apiBase,
  2. String cookie, {
  3. Client? client,
})

Fetches the user's accessible projects from <apiBase>/v1/user — the applications + applications_admin arrays merged and deduplicated. Authentication uses the full cookie string as a Cookie: header.

Implementation

Future<List<String>> fetchCodeMieProjects(
  String apiBase,
  String cookie, {
  http.Client? client,
}) async {
  final httpClient = client ?? http.Client();
  final ownsClient = client == null;
  try {
    final response = await httpClient
        .get(Uri.parse('$apiBase/v1/user'), headers: {'cookie': cookie})
        .timeout(const Duration(seconds: 30));
    if (response.statusCode < 200 || response.statusCode >= 300) {
      throw ConfigException(
        'CodeMie user info failed (${response.statusCode})',
      );
    }
    final decoded = jsonDecode(response.body);
    if (decoded is! Map) return const [];
    return _collectAppNames(decoded);
  } finally {
    if (ownsClient) httpClient.close();
  }
}