feat(authentication)!: add repo in callback usecases (close #55)
This commit is contained in:
parent
f123e537ae
commit
ca70f2eb1d
@ -23,6 +23,7 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart';
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
|
||||
FutureOrResult<int?> onSignUpSuccess(
|
||||
AuthenticationRepository<int> repo,
|
||||
Account? account,
|
||||
WyattForm form,
|
||||
) async {
|
||||
@ -35,9 +36,15 @@ FutureOrResult<int?> onSignUpSuccess(
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -30,11 +30,15 @@ import 'package:wyatt_form_bloc/wyatt_form_bloc.dart';
|
||||
import 'package:wyatt_type_utils/wyatt_type_utils.dart';
|
||||
|
||||
typedef OnSignUpSuccess<T> = FutureOrResult<T?> Function(
|
||||
AuthenticationRepository<T> repo,
|
||||
Account? account,
|
||||
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>
|
||||
extends AuthenticationRepository<T> {
|
||||
@ -149,6 +153,7 @@ class AuthenticationRepositoryImpl<T extends Object>
|
||||
await _authenticationLocalDataSource.storeAccount(account);
|
||||
if (_onSignUpSuccess.isNotNull) {
|
||||
final dataResult = await _onSignUpSuccess!.call(
|
||||
this,
|
||||
account,
|
||||
_formRepository.accessForm(AuthFormName.signUpForm).clone(),
|
||||
);
|
||||
@ -232,7 +237,7 @@ class AuthenticationRepositoryImpl<T extends Object>
|
||||
_signUpStream.stream.asBroadcastStream(),
|
||||
_authenticationRemoteDataSource.streamAccount().map((account) async {
|
||||
if (_onAccountChanges.isNotNull && !_pause) {
|
||||
final dataResult = await _onAccountChanges!.call(account);
|
||||
final dataResult = await _onAccountChanges!.call(this, account);
|
||||
return dataResult.map((data) {
|
||||
_authenticationLocalDataSource.storeData(data);
|
||||
return AccountWrapperModel(account, data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user