diff --git a/mnemo_cards_backend/lib/api/v2/auth_api_v2.dart b/mnemo_cards_backend/lib/api/v2/auth_api_v2.dart index 1568a76..5f876a0 100644 --- a/mnemo_cards_backend/lib/api/v2/auth_api_v2.dart +++ b/mnemo_cards_backend/lib/api/v2/auth_api_v2.dart @@ -238,17 +238,26 @@ class AuthApiV2 { Future authenticateTelegramWebApp(Request request) async { try { final body = await request.readAsString(); - log('Telegram Web App auth request body: ${body.length} chars', name: 'AuthApiV2'); + log('Telegram Web App auth request body length: ${body.length} chars', name: 'AuthApiV2'); + log('Telegram Web App auth request body (first 200 chars): ${body.length > 200 ? body.substring(0, 200) : body}', name: 'AuthApiV2'); + + Map json; + try { + json = jsonDecode(body) as Map; + } catch (e, s) { + log('Telegram Web App auth: Failed to parse JSON body: $e', error: e, stackTrace: s, name: 'AuthApiV2'); + return _badRequest('Invalid JSON in request body: $e'); + } - final json = jsonDecode(body) as Map; final initData = json['initData'] as String?; if (initData == null || initData.isEmpty) { - log('Telegram Web App auth: initData is null or empty', name: 'AuthApiV2'); + log('Telegram Web App auth: initData is null or empty. JSON keys: ${json.keys.toList()}', name: 'AuthApiV2'); return _badRequest('Telegram Web App init data is required'); } log('Telegram Web App auth: initData received, length: ${initData.length}', name: 'AuthApiV2'); + log('Telegram Web App auth: initData preview (first 100 chars): ${initData.length > 100 ? initData.substring(0, 100) : initData}', name: 'AuthApiV2'); // Use the existing telegram utils to get user ID final telegramUtils = TelegramUtils(); diff --git a/mnemo_cards_web_v2/lib/domain/services/http_repository_v2.dart b/mnemo_cards_web_v2/lib/domain/services/http_repository_v2.dart index 4283f3f..97a5b7d 100644 --- a/mnemo_cards_web_v2/lib/domain/services/http_repository_v2.dart +++ b/mnemo_cards_web_v2/lib/domain/services/http_repository_v2.dart @@ -430,6 +430,11 @@ class HttpRepositoryV2 { return null; } on DioException catch (e) { + log( + 'Telegram Web App auth DioException: ${e.response?.statusCode}, ' + 'message: ${e.message}, data: ${e.response?.data}', + name: 'HttpRepositoryV2', + ); if (e.error is ApiException) { rethrow; }