refactor(authentication): controle cache checking

This commit is contained in:
Hugo Pointcheval 2023-05-06 11:26:40 +02:00
parent 553b6763af
commit 93873e3134
Signed by: hugo
GPG Key ID: 3AAC487E131E00BC

View File

@ -40,6 +40,7 @@ abstract class AuthenticationCubit<Data>
/// {@macro authentication_cubit}
AuthenticationCubit({
required this.authenticationRepository,
this.checkForCachedAccountOnInitialization = true,
}) : super(const AuthenticationState.unknown()) {
_init();
}
@ -47,6 +48,9 @@ abstract class AuthenticationCubit<Data>
/// The authentication repository.
final AuthenticationRepository<Data> authenticationRepository;
/// Automatically check for cached account on initialization.
final bool checkForCachedAccountOnInitialization;
/// The latest session.
AuthenticationSession<Data>? _latestSession;
@ -56,7 +60,9 @@ abstract class AuthenticationCubit<Data>
_listenForAuthenticationChanges();
/// Check if there is a cached account.
await authenticationRepository.checkForCachedAccount();
if (checkForCachedAccountOnInitialization) {
await checkForCachedAccount();
}
}
void _listenForAuthenticationChanges() {
@ -148,6 +154,10 @@ abstract class AuthenticationCubit<Data>
),
).call();
/// Checks for cached account.
FutureOr<void> checkForCachedAccount() async =>
authenticationRepository.checkForCachedAccount();
/// Returns latest session.
///
/// Contains latest event and latest session data (account + extra data)