From f0ed08bd49f06d48d7db392b6c767618d2bb0c1a Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Wed, 16 Nov 2022 19:52:24 -0500 Subject: [PATCH] feat(auth): add reloadCache method in AuthenticationCubit --- .../authentication/cubit/authentication_cubit.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 7da6ff32..cf648917 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 @@ -56,6 +56,19 @@ class AuthenticationCubit extends Cubit> { }); } + /// If authenticated, re-emits state with data freshly loaded from cache. + FutureOr reloadCache() async { + if (state.status == AuthenticationStatus.authenticated) { + final data = await _authenticationRepository.getCache(); + emit( + data.fold( + AuthenticationState.authenticated, + (error) => state, + ), + ); + } + } + FutureOr signOut() { // TODO(hpcl): maybe force unauthenticated by emitting an event _authenticationRepository.signOut();