Skip to content

Commit 9c25c6b

Browse files
committed
refactor(auth_inmemory): asynchronously emit initial auth state
- Use Future to schedule the initial auth state emission - Ensure subscribers have time to listen before the first event - Maintain consistency with real auth client behavior - Improve logging to reflect scheduled initialization
1 parent f48dc05 commit 9c25c6b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/src/auth_inmemory.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ class AuthInmemory implements AuthClient {
2424
);
2525
_currentUser = initialUser;
2626
_currentToken = initialToken;
27-
if (_currentUser != null) {
28-
_authStateController.add(_currentUser);
29-
_logger.finer('Added initial user to authStateController.');
30-
}
31-
_logger.fine('Initialization complete.');
27+
// To mimic a "hot" stream like a real auth client, we immediately
28+
// emit the initial state. We use a Future to schedule this for the next
29+
// event-loop microtask, ensuring that subscribers (like AppBloc) have
30+
// time to listen before the first event is sent.
31+
Future(() => _authStateController.add(_currentUser));
32+
_logger
33+
..finer(
34+
'Scheduled initial user ($_currentUser) to be added to authStateController.',
35+
)
36+
..fine('AuthInmemory initialization complete.');
3237
}
3338
final Logger _logger;
3439
final Uuid _uuid = const Uuid();

0 commit comments

Comments
 (0)