feat(auth): add reloadCache method in AuthenticationCubit

This commit is contained in:
Hugo Pointcheval 2022-11-16 19:52:24 -05:00
parent 390fb81b1e
commit f0ed08bd49
Signed by: hugo
GPG Key ID: A9E8E9615379254F

View File

@ -56,6 +56,19 @@ class AuthenticationCubit<Extra> extends Cubit<AuthenticationState<Extra>> {
});
}
/// If authenticated, re-emits state with data freshly loaded from cache.
FutureOr<void> reloadCache() async {
if (state.status == AuthenticationStatus.authenticated) {
final data = await _authenticationRepository.getCache();
emit(
data.fold(
AuthenticationState<Extra>.authenticated,
(error) => state,
),
);
}
}
FutureOr<void> signOut() {
// TODO(hpcl): maybe force unauthenticated by emitting an event
_authenticationRepository.signOut();