Skip to content
Merged

fix sse #3313

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/bloc/auth_bloc/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> with TrezorAuthMixin {
// Log and continue to clear local auth state so UI can recover.
_log.shout('Error during sign out, proceeding to reset state', e, s);
} finally {
// Explicitly disconnect SSE on sign-out
_log.info('User signed out, disconnecting SSE...');
_kdfSdk.streaming.disconnect();

await _authChangesSubscription?.cancel();
emit(AuthBlocState.initial());
}
Expand Down Expand Up @@ -139,6 +143,11 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> with TrezorAuthMixin {

_log.info('Successfully logged in to wallet');
emit(AuthBlocState.loggedIn(currentUser));

// Explicitly connect SSE after successful login
_log.info('User authenticated, connecting SSE for streaming...');
_kdfSdk.streaming.connectIfNeeded();

_listenToAuthStateChanges();
} catch (e, s) {
if (e is AuthException) {
Expand Down Expand Up @@ -453,6 +462,17 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> with TrezorAuthMixin {
? AuthorizeMode.logIn
: AuthorizeMode.noLogin;
add(AuthModeChanged(mode: event, currentUser: user));

// Tie SSE connection lifecycle to authentication state
if (user != null) {
// User authenticated - connect SSE for balance/tx history streaming
_log.info('User authenticated, connecting SSE for streaming...');
_kdfSdk.streaming.connectIfNeeded();
} else {
// User signed out - disconnect SSE to clean up resources
_log.info('User signed out, disconnecting SSE...');
_kdfSdk.streaming.disconnect();
}
});
}

Expand Down
Loading