Skip to content

Commit c56f337

Browse files
committed
refactor(authentication): improve cooldown timer management
- Fixed a memory leak in AuthenticationBloc by ensuring the cooldown timer is properly cancelled when the BLoC is closed. - Removed redundant logic from the RequestCodePage UI, making the AuthenticationBloc the single source of truth for cooldown state transitions.
1 parent 1727d88 commit c56f337

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/authentication/bloc/authentication_bloc.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class AuthenticationBloc
3838

3939
final AuthRepository _authenticationRepository;
4040
late final StreamSubscription<User?> _userAuthSubscription;
41+
Timer? _cooldownTimer;
4142

4243
/// Handles [_AuthenticationUserChanged] events.
4344
Future<void> _onAuthenticationUserChanged(
@@ -83,7 +84,8 @@ class AuthenticationBloc
8384
),
8485
);
8586

86-
Timer(
87+
_cooldownTimer?.cancel();
88+
_cooldownTimer = Timer(
8789
_requestCodeCooldownDuration,
8890
() => add(const AuthenticationCooldownCompleted()),
8991
);
@@ -168,6 +170,7 @@ class AuthenticationBloc
168170
@override
169171
Future<void> close() {
170172
_userAuthSubscription.cancel();
173+
_cooldownTimer?.cancel();
171174
return super.close();
172175
}
173176

lib/authentication/view/request_code_page.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,6 @@ class _EmailLinkFormState extends State<_EmailLinkForm> {
200200
setState(() {
201201
_cooldownSeconds = 0;
202202
});
203-
context
204-
.read<AuthenticationBloc>()
205-
.add(const AuthenticationCooldownCompleted());
206203
}
207204
});
208205
}

0 commit comments

Comments
 (0)