From 93873e3134f0d4acc58e22f1fa24eae52633462f Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Sat, 6 May 2023 11:26:40 +0200 Subject: [PATCH] refactor(authentication): controle cache checking --- .../authentication/cubit/authentication_cubit.dart | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_cubit.dart b/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_cubit.dart index e5abf6ec..20b238c5 100644 --- a/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_cubit.dart +++ b/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_cubit.dart @@ -40,6 +40,7 @@ abstract class AuthenticationCubit /// {@macro authentication_cubit} AuthenticationCubit({ required this.authenticationRepository, + this.checkForCachedAccountOnInitialization = true, }) : super(const AuthenticationState.unknown()) { _init(); } @@ -47,6 +48,9 @@ abstract class AuthenticationCubit /// The authentication repository. final AuthenticationRepository authenticationRepository; + /// Automatically check for cached account on initialization. + final bool checkForCachedAccountOnInitialization; + /// The latest session. AuthenticationSession? _latestSession; @@ -56,7 +60,9 @@ abstract class AuthenticationCubit _listenForAuthenticationChanges(); /// Check if there is a cached account. - await authenticationRepository.checkForCachedAccount(); + if (checkForCachedAccountOnInitialization) { + await checkForCachedAccount(); + } } void _listenForAuthenticationChanges() { @@ -148,6 +154,10 @@ abstract class AuthenticationCubit ), ).call(); + /// Checks for cached account. + FutureOr checkForCachedAccount() async => + authenticationRepository.checkForCachedAccount(); + /// Returns latest session. /// /// Contains latest event and latest session data (account + extra data)