From 34eccb7db5c252cec282459f77402d779945ac99 Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Tue, 10 Feb 2026 18:36:18 +0300 Subject: [PATCH] feat: Enhance OAuth error state to include specific registration validation errors and pass email in the verification request. --- .../bloc/oauth_cubit/oauth_cubit.dart | 29 +++++++++++++++---- .../bloc/oauth_cubit/oauth_state.dart | 7 ++++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/features/auth/presentation/bloc/oauth_cubit/oauth_cubit.dart b/lib/features/auth/presentation/bloc/oauth_cubit/oauth_cubit.dart index daf156a8..a066c959 100644 --- a/lib/features/auth/presentation/bloc/oauth_cubit/oauth_cubit.dart +++ b/lib/features/auth/presentation/bloc/oauth_cubit/oauth_cubit.dart @@ -36,9 +36,29 @@ class OAuthCubit extends Cubit with RegistrationDateCacheMixin { final emailErrors = errors?['email'] as List?; final phoneErrors = errors?['phone'] as List?; - if ((emailErrors != null && emailErrors.isNotEmpty) || (phoneErrors != null && phoneErrors.isNotEmpty)) { - // Это ошибка валидации - нужно показать экран подтверждения - emit(const OAuthState.error(errorMessage: 'validation_error')); + final errorsList = []; + if (emailErrors != null && emailErrors.isNotEmpty) { + for (final error in emailErrors) { + final errorStr = error.toString(); + if (errorStr.contains('Некорректный формат email')) { + errorsList.add(RegistrationValidationErrors.incorrectEmailFormat); + } + if (errorStr.contains('почта уже существует') || errorStr.contains('Эл. почта уже существует')) { + errorsList.add(RegistrationValidationErrors.emailExist); + } + } + } + if (phoneErrors != null && phoneErrors.isNotEmpty) { + for (final error in phoneErrors) { + final errorStr = error.toString(); + if (errorStr.contains('phone уже существует') || errorStr.contains('телефон уже существует')) { + errorsList.add(RegistrationValidationErrors.phoneExist); + } + } + } + + if (errorsList.isNotEmpty) { + emit(OAuthState.error(errorMessage: 'validation_error', registrationValidationErrors: errorsList)); } else { emit(OAuthState.error(errorMessage: e.toString())); } @@ -126,7 +146,7 @@ class OAuthCubit extends Cubit with RegistrationDateCacheMixin { try { emit(const OAuthState.loading()); log('OAuthCubit: Requesting verification code for email: $email, phone: $phone'); - final response = await authRepository.requestOAuthVerification(email: null, phone: phone); + final response = await authRepository.requestOAuthVerification(email: email, phone: phone); if (response != null) { log('OAuthCubit: Verification code requested successfully, masked email: ${response.email}'); } @@ -188,4 +208,3 @@ class OAuthCubit extends Cubit with RegistrationDateCacheMixin { } } -enum RegistrationValidationErrors { incorrectEmailFormat, emailExist, phoneExist, incorrectDateOfBirthFormat } diff --git a/lib/features/auth/presentation/bloc/oauth_cubit/oauth_state.dart b/lib/features/auth/presentation/bloc/oauth_cubit/oauth_state.dart index 7da9ab7c..517222de 100644 --- a/lib/features/auth/presentation/bloc/oauth_cubit/oauth_state.dart +++ b/lib/features/auth/presentation/bloc/oauth_cubit/oauth_state.dart @@ -10,5 +10,10 @@ abstract class OAuthState with _$OAuthState { const factory OAuthState.loaded({required String token}) = OAuthStateLoaded; - const factory OAuthState.error({required String errorMessage}) = OAuthStateError; + const factory OAuthState.error({ + required String errorMessage, + List? registrationValidationErrors, + }) = OAuthStateError; } + +enum RegistrationValidationErrors { incorrectEmailFormat, emailExist, phoneExist, incorrectDateOfBirthFormat }