fix(authentication): initialize account stream transformer

This commit is contained in:
Hugo Pointcheval 2022-12-29 17:38:37 +01:00
parent 828c1ace6f
commit 13fc4aa875
Signed by: hugo
GPG Key ID: 3AAC487E131E00BC

View File

@ -44,6 +44,19 @@ class AuthenticationRepositoryImpl<T extends Object>
}) : _authChangeListener = onAuthChange, }) : _authChangeListener = onAuthChange,
_accountStreamTransformer = accountStreamTransformer { _accountStreamTransformer = accountStreamTransformer {
_formRepository = formRepository ?? FormRepositoryImpl(); _formRepository = formRepository ?? FormRepositoryImpl();
_accountStreamTransformer ??= (input) => input
.where((event) => event is! SignUpAuthChangeEvent)
.map<FutureOrResult<AccountWrapper<T>>>((event) async {
if (listener == null) {
return Ok(AccountWrapperModel<T>(event.account, null));
}
// Handle sign in, sign out and refresh
final dataResult = await listener!.call(this, event);
return dataResult.map((data) {
authenticationCacheDataSource.storeData(data);
return AccountWrapperModel(event.account, data);
});
});
if (formRepository != null) { if (formRepository != null) {
return; return;
} }
@ -90,19 +103,6 @@ class AuthenticationRepositoryImpl<T extends Object>
name: AuthFormName.passwordResetForm, name: AuthFormName.passwordResetForm,
), ),
); );
_accountStreamTransformer ??= (input) => input
.where((event) => event is! SignUpAuthChangeEvent)
.map<FutureOrResult<AccountWrapper<T>>>((event) async {
if (listener == null) {
return Ok(AccountWrapperModel<T>(event.account, null));
}
// Handle sign in, sign out and refresh
final dataResult = await listener!.call(this, event);
return dataResult.map((data) {
authenticationCacheDataSource.storeData(data);
return AccountWrapperModel(event.account, data);
});
});
} }
final AuthenticationCacheDataSource<T> authenticationCacheDataSource; final AuthenticationCacheDataSource<T> authenticationCacheDataSource;
final AuthenticationRemoteDataSource authenticationRemoteDataSource; final AuthenticationRemoteDataSource authenticationRemoteDataSource;