loginWithCode method

Future<LoginResponse> loginWithCode(
  1. String code
)

Login with feedback code

Returns authentication tokens Throws DioException if the request fails

Implementation

Future<LoginResponse> loginWithCode(String code) async {
  DebugLogger.log('[AuthRemoteDataSource] === loginWithCode() called ===');
  DebugLogger.log('[AuthRemoteDataSource] Code length: ${code.length} chars');
  DebugLogger.log(
    '[AuthRemoteDataSource] API Endpoint: $baseUrl/idm/v1/auth/feedback/login',
  );

  final requestData = {'code': code, 'app': 'Launcher'};
  DebugLogger.log('[AuthRemoteDataSource] Request data: $requestData');

  try {
    final response = await dio.post(
      '$baseUrl/idm/v1/auth/feedback/login',
      data: requestData,
    );

    DebugLogger.log('[AuthRemoteDataSource] ✅ Login API call successful');
    DebugLogger.log('[AuthRemoteDataSource] Response status: ${response.statusCode}');

    final loginResponse = LoginResponse.fromJson(response.data);
    DebugLogger.log('[AuthRemoteDataSource] Parsed response:');
    DebugLogger.log('[AuthRemoteDataSource]   - Status: ${loginResponse.status}');
    DebugLogger.log(
      '[AuthRemoteDataSource]   - Has data: ${loginResponse.data != null}',
    );
    DebugLogger.log('[AuthRemoteDataSource]   - Error: ${loginResponse.error}');

    if (loginResponse.data != null) {
      DebugLogger.log('[AuthRemoteDataSource] Token data:');
      DebugLogger.log(
        '[AuthRemoteDataSource]   - Token: ${loginResponse.data!.token.substring(0, 20)}... (${loginResponse.data!.token.length} chars)',
      );
      DebugLogger.log(
        '[AuthRemoteDataSource]   - RefreshToken: ${loginResponse.data!.refreshToken.substring(0, 20)}... (${loginResponse.data!.refreshToken.length} chars)',
      );
      if (loginResponse.data!.reportingToken != null) {
        DebugLogger.log(
          '[AuthRemoteDataSource]   - ReportingToken: ${loginResponse.data!.reportingToken!.substring(0, 20)}... (${loginResponse.data!.reportingToken!.length} chars)',
        );
      }
    }

    return loginResponse;
  } on DioException catch (e) {
    DebugLogger.log('[AuthRemoteDataSource] ❌ DioException occurred during login');
    DebugLogger.log('[AuthRemoteDataSource] Error type: ${e.type}');
    DebugLogger.log('[AuthRemoteDataSource] Status code: ${e.response?.statusCode}');
    DebugLogger.log('[AuthRemoteDataSource] Error message: ${e.message}');

    if (e.response?.data != null) {
      DebugLogger.log(
        '[AuthRemoteDataSource] Error response data: ${e.response?.data}',
      );
    }

    rethrow;
  } catch (e) {
    DebugLogger.log('[AuthRemoteDataSource] ❌ Unexpected error during login: $e');
    rethrow;
  }
}