forked from eatvio/eatvio_app
feat(auth): align password policy and handle 429 responses
- map 429 Retry-After to a localized toast in AuthCubit - enforce the 8-character minimum on registration v1 and add the hint - surface errors.password in registration v2 - show password errors from 422 responses in the reset flow - add ru/en localization strings and regenerate l10n - add a regression test for the 429/Retry-After path
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/firebase_api.dart';
|
||||
import 'package:eatvio_app/core/prefs.dart';
|
||||
import 'package:eatvio_app/core/prefs_keys.dart';
|
||||
@@ -9,6 +10,7 @@ import 'package:eatvio_app/core/utils/toasts.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/bloc/auth_cubit/auth_state.dart';
|
||||
import 'package:eatvio_app/features/auth/repositories/auth_repository.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
||||
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
||||
@@ -42,6 +44,25 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString());
|
||||
if (e is DioException && e.response?.statusCode == 429) {
|
||||
final response = e.response;
|
||||
final data = response?.data;
|
||||
final error = data is Map ? data['error'] : null;
|
||||
final retryAfter =
|
||||
response?.headers.value('retry-after') ??
|
||||
(error is Map ? error['retry_after']?.toString() : null);
|
||||
final serverMessage = error is Map && error['message'] is String
|
||||
? error['message'] as String
|
||||
: data is Map && data['message'] is String
|
||||
? data['message'] as String
|
||||
: null;
|
||||
final message = retryAfter != null && retryAfter.isNotEmpty
|
||||
? S.current.too_many_login_attempts(int.tryParse(retryAfter) ?? 0)
|
||||
: serverMessage ?? S.current.too_many_login_attempts_no_retry;
|
||||
showErrorToast(message);
|
||||
emit(AuthState.error(errorMessage: message));
|
||||
return false;
|
||||
}
|
||||
showErrorToast('Неверный адрес электронной почты или пароль');
|
||||
emit(AuthState.error(errorMessage: '$e'));
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user