diff --git a/lib/authentication/bloc/authentication_bloc.dart b/lib/authentication/bloc/authentication_bloc.dart index 62e197e..8f8a75b 100644 --- a/lib/authentication/bloc/authentication_bloc.dart +++ b/lib/authentication/bloc/authentication_bloc.dart @@ -47,6 +47,7 @@ class AuthenticationBloc final AuthRepository _authenticationRepository; late final StreamSubscription _userAuthSubscription; + Timer? _cooldownTimer; /// Handles [_AuthenticationStatusChanged] events. Future _onAuthenticationStatusChanged( @@ -97,7 +98,8 @@ class AuthenticationBloc ); // Start a timer to transition out of cooldown - Timer( + _cooldownTimer?.cancel(); + _cooldownTimer = Timer( _requestCodeCooldownDuration, () => add(const AuthenticationCooldownCompleted()), ); @@ -213,6 +215,7 @@ class AuthenticationBloc @override Future close() { _userAuthSubscription.cancel(); + _cooldownTimer?.cancel(); return super.close(); } } diff --git a/lib/authentication/view/request_code_page.dart b/lib/authentication/view/request_code_page.dart index f5bf9f6..4c94575 100644 --- a/lib/authentication/view/request_code_page.dart +++ b/lib/authentication/view/request_code_page.dart @@ -222,10 +222,8 @@ class _EmailLinkFormState extends State<_EmailLinkForm> { setState(() { _cooldownSeconds = 0; }); - // Optionally, trigger an event to reset the bloc state if needed - context - .read() - .add(const AuthenticationCooldownCompleted()); + // The BLoC handles resetting its own state. The UI timer is only + // responsible for updating the countdown on the screen. } }); }