AuthenticationBloc constructor

AuthenticationBloc({
  1. required AuthRepository authRepository,
  2. required UserRepository userRepository,
  3. required NotificationRepository notificationRepository,
  4. required AppLogger logger,
})

Creates the bloc, wiring repositories, logger, and event handlers.

Implementation

AuthenticationBloc({
  required AuthRepository authRepository,
  required UserRepository userRepository,
  required NotificationRepository notificationRepository,
  required AppLogger logger,
}) : _authRepository = authRepository,
     _userRepository = userRepository,
     _notificationRepository = notificationRepository,
     _logger = logger,
     super(const AuthenticationState.unknown()) {
  on<StartupAuthResolved>(_onStartupAuthResolved);
  on<StartLiveListening>(_onStartLiveListening);
  // sequential(): _authRepository.statusChanges can fire a fast
  // `unauthenticated` event while a slower `authenticated` resolution
  // (the await _authRepository.resolveUser(...) below) is still in
  // flight — without this, the faster event could be processed first and
  // then get overwritten by the slower one's stale result.
  on<_AuthStatusChanged>(_onAuthStatusChanged, transformer: sequential());
  on<_AppUserChanged>(_onAppUserChanged);
  // droppable(): this handler has no other re-entrancy guard, so a
  // double-tap logout would otherwise call AuthRepository.logout() twice.
  on<AppLogoutRequested>(_onLogoutRequested, transformer: droppable());
}