refactor: implement lazy initialization for global BlocProviders and enhance Firebase initialization with timeout handling

This commit is contained in:
mso7nueh
2026-01-13 12:22:22 +03:00
parent a778257215
commit d206e7ec12
13 changed files with 161 additions and 41 deletions

View File

@@ -38,18 +38,25 @@ class AuthCubit extends Cubit<AuthState> {
}
Future<void> initializeUser() async {
await registerAnonymousPushToken();
if (await TokenStorage.haveTokenInStorage()) {
final profile = await profileRepository.getMyProfile();
if (profile.emailVerifiedAt != null) {
await registerPushToken();
AppRouter.navigatorKey.currentContext?.go(RouteConstants.feedScreen);
return;
}
AppRouter.navigatorKey.currentContext?.go(RouteConstants.verifyEmailScreen);
} else {
try {
await registerAnonymousPushToken();
FlutterNativeSplash.remove();
if (await TokenStorage.haveTokenInStorage()) {
final profile = await profileRepository.getMyProfile();
if (profile.emailVerifiedAt != null) {
await registerPushToken();
FlutterNativeSplash.remove();
AppRouter.navigatorKey.currentContext?.go(RouteConstants.feedScreen);
return;
}
FlutterNativeSplash.remove();
AppRouter.navigatorKey.currentContext?.go(RouteConstants.verifyEmailScreen);
} else {
FlutterNativeSplash.remove();
}
} catch (e) {
log('Error in initializeUser: $e');
FlutterNativeSplash.remove(); // Убираем сплэш даже при ошибке
rethrow;
}
}