feat(authentication)!: add repo in callback usecases (close #55) #61
| @ -23,6 +23,7 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; | |||||||
| import 'package:wyatt_architecture/wyatt_architecture.dart'; | import 'package:wyatt_architecture/wyatt_architecture.dart'; | ||||||
| 
 | 
 | ||||||
| FutureOrResult<int?> onSignUpSuccess( | FutureOrResult<int?> onSignUpSuccess( | ||||||
|  |   AuthenticationRepository<int> repo, | ||||||
|   Account? account, |   Account? account, | ||||||
|   WyattForm form, |   WyattForm form, | ||||||
| ) async { | ) async { | ||||||
| @ -35,9 +36,15 @@ FutureOrResult<int?> onSignUpSuccess( | |||||||
|   return const Ok<int, AppException>(id); |   return const Ok<int, AppException>(id); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| FutureOrResult<int?> onAccountChanges(Account? account) async { | FutureOrResult<int?> onAccountChanges( | ||||||
|  |   AuthenticationRepository<int> repo, | ||||||
|  |   Account? account, | ||||||
|  | ) async { | ||||||
|   final id = Random().nextInt(1000); |   final id = Random().nextInt(1000); | ||||||
|   debugPrint('onAccountChanges: $account, generatedId: $id'); |   final token = | ||||||
|  |       await repo.getIdentityToken().fold((value) => value, (error) => 'null'); | ||||||
|  | 
 | ||||||
|  |   debugPrint('onAccountChanges: $account, token: $token, generatedId: $id'); | ||||||
|   return Ok<int, AppException>(id); |   return Ok<int, AppException>(id); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -30,11 +30,15 @@ import 'package:wyatt_form_bloc/wyatt_form_bloc.dart'; | |||||||
| import 'package:wyatt_type_utils/wyatt_type_utils.dart'; | import 'package:wyatt_type_utils/wyatt_type_utils.dart'; | ||||||
| 
 | 
 | ||||||
| typedef OnSignUpSuccess<T> = FutureOrResult<T?> Function( | typedef OnSignUpSuccess<T> = FutureOrResult<T?> Function( | ||||||
|  |   AuthenticationRepository<T> repo, | ||||||
|   Account? account, |   Account? account, | ||||||
|   WyattForm form, |   WyattForm form, | ||||||
| ); | ); | ||||||
| 
 | 
 | ||||||
| typedef OnAuthChange<T> = FutureOrResult<T?> Function(Account? account); | typedef OnAuthChange<T> = FutureOrResult<T?> Function( | ||||||
|  |   AuthenticationRepository<T> repo, | ||||||
|  |   Account? account, | ||||||
|  | ); | ||||||
| 
 | 
 | ||||||
| class AuthenticationRepositoryImpl<T extends Object> | class AuthenticationRepositoryImpl<T extends Object> | ||||||
|     extends AuthenticationRepository<T> { |     extends AuthenticationRepository<T> { | ||||||
| @ -149,6 +153,7 @@ class AuthenticationRepositoryImpl<T extends Object> | |||||||
|           await _authenticationLocalDataSource.storeAccount(account); |           await _authenticationLocalDataSource.storeAccount(account); | ||||||
|           if (_onSignUpSuccess.isNotNull) { |           if (_onSignUpSuccess.isNotNull) { | ||||||
|             final dataResult = await _onSignUpSuccess!.call( |             final dataResult = await _onSignUpSuccess!.call( | ||||||
|  |               this, | ||||||
|               account, |               account, | ||||||
|               _formRepository.accessForm(AuthFormName.signUpForm).clone(), |               _formRepository.accessForm(AuthFormName.signUpForm).clone(), | ||||||
|             ); |             ); | ||||||
| @ -232,7 +237,7 @@ class AuthenticationRepositoryImpl<T extends Object> | |||||||
|         _signUpStream.stream.asBroadcastStream(), |         _signUpStream.stream.asBroadcastStream(), | ||||||
|         _authenticationRemoteDataSource.streamAccount().map((account) async { |         _authenticationRemoteDataSource.streamAccount().map((account) async { | ||||||
|           if (_onAccountChanges.isNotNull && !_pause) { |           if (_onAccountChanges.isNotNull && !_pause) { | ||||||
|             final dataResult = await _onAccountChanges!.call(account); |             final dataResult = await _onAccountChanges!.call(this, account); | ||||||
|             return dataResult.map((data) { |             return dataResult.map((data) { | ||||||
|               _authenticationLocalDataSource.storeData(data); |               _authenticationLocalDataSource.storeData(data); | ||||||
|               return AccountWrapperModel(account, data); |               return AccountWrapperModel(account, data); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user