diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/app/app.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/app/app.dart index 9bf7f5cd..c73ab7b8 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/app/app.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/app/app.dart @@ -3,7 +3,7 @@ // ----- // File: app.dart // Created Date: 19/08/2022 12:05:38 -// Last Modified: Thu Nov 10 2022 +// Last Modified: Wed Nov 23 2022 // ----- // Copyright (c) 2022 @@ -21,7 +21,7 @@ import 'package:wyatt_form_bloc/wyatt_form_bloc.dart'; import 'package:wyatt_type_utils/wyatt_type_utils.dart'; import 'package:wyatt_architecture/wyatt_architecture.dart'; -FutureResult onSignUpSuccess( +FutureOrResult onSignUpSuccess( Account? account, WyattForm form, ) async { @@ -34,7 +34,7 @@ FutureResult onSignUpSuccess( return const Ok(id); } -FutureResult onAccountChanges(Account? account) async { +FutureOrResult onAccountChanges(Account? account) async { final id = Random().nextInt(1000); debugPrint('onAccountChanges: $account, generatedId: $id'); return Ok(id); diff --git a/packages/wyatt_authentication_bloc/lib/src/data/repositories/authentication_repository_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/repositories/authentication_repository_impl.dart index 134c1bf8..1d628fed 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/repositories/authentication_repository_impl.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/repositories/authentication_repository_impl.dart @@ -29,12 +29,12 @@ import 'package:wyatt_authentication_bloc/src/domain/repositories/authentication import 'package:wyatt_form_bloc/wyatt_form_bloc.dart'; import 'package:wyatt_type_utils/wyatt_type_utils.dart'; -typedef OnSignUpSuccess = FutureResult Function( +typedef OnSignUpSuccess = FutureOrResult Function( Account? account, WyattForm form, ); -typedef OnAuthChange = FutureResult Function(Account? account); +typedef OnAuthChange = FutureOrResult Function(Account? account); class AuthenticationRepositoryImpl extends AuthenticationRepository { @@ -46,7 +46,7 @@ class AuthenticationRepositoryImpl final OnSignUpSuccess? _onSignUpSuccess; final OnAuthChange? _onAccountChanges; - final StreamController>> _signUpStream = + final StreamController>> _signUpStream = StreamController(); bool _pause = false; // Semaphore @@ -93,7 +93,7 @@ class AuthenticationRepositoryImpl FormRepository get formRepository => _formRepository; @override - FutureResult signInWithEmailAndPassword({ + FutureOrResult signInWithEmailAndPassword({ required String email, required String password, }) => @@ -111,7 +111,7 @@ class AuthenticationRepositoryImpl ); @override - FutureResult signOut() => + FutureOrResult signOut() => Result.tryCatchAsync( () async { await _authenticationRemoteDataSource.signOut(); @@ -121,7 +121,7 @@ class AuthenticationRepositoryImpl ); @override - FutureResult signUp({ + FutureOrResult signUp({ required String email, required String password, }) => @@ -157,28 +157,28 @@ class AuthenticationRepositoryImpl ); @override - FutureResult destroyCache() => + FutureOrResult destroyCache() => Result.tryCatchAsync( _authenticationLocalDataSource.destroy, (error) => error, ); @override - FutureResult> getCache() => + FutureOrResult> getCache() => Result.tryCatchAsync, AppException, AppException>( _authenticationLocalDataSource.load, (error) => error, ); @override - FutureResult getAccount() => + FutureOrResult getAccount() => Result.tryCatchAsync( _authenticationLocalDataSource.loadAccount, (error) => error, ); @override - FutureResult setAccount( + FutureOrResult setAccount( Account account, ) => Result.tryCatchAsync( @@ -189,14 +189,14 @@ class AuthenticationRepositoryImpl ); @override - FutureResult getData() => + FutureOrResult getData() => Result.tryCatchAsync( _authenticationLocalDataSource.loadData, (error) => error, ); @override - FutureResult setData( + FutureOrResult setData( T? data, ) => Result.tryCatchAsync( @@ -207,14 +207,14 @@ class AuthenticationRepositoryImpl ); @override - FutureResult getIdentityToken() => + FutureOrResult getIdentityToken() => Result.tryCatchAsync( _authenticationRemoteDataSource.getIdentityToken, (error) => error, ); @override - Stream>> streamAccount() => MergeStream([ + Stream>> streamAccount() => MergeStream([ _signUpStream.stream.asBroadcastStream(), _authenticationRemoteDataSource.streamAccount().map((account) async { if (_onAccountChanges.isNotNull && !_pause) { @@ -231,7 +231,7 @@ class AuthenticationRepositoryImpl ]); @override - FutureResult confirmPasswordReset({ + FutureOrResult confirmPasswordReset({ required String code, required String newPassword, }) => @@ -246,7 +246,7 @@ class AuthenticationRepositoryImpl ); @override - FutureResult sendEmailVerification() => + FutureOrResult sendEmailVerification() => Result.tryCatchAsync( () async { await _authenticationRemoteDataSource.sendEmailVerification(); @@ -255,7 +255,7 @@ class AuthenticationRepositoryImpl ); @override - FutureResult sendPasswordResetEmail({required String email}) => + FutureOrResult sendPasswordResetEmail({required String email}) => Result.tryCatchAsync( () async { await _authenticationRemoteDataSource.sendPasswordResetEmail( @@ -266,7 +266,7 @@ class AuthenticationRepositoryImpl ); @override - FutureResult signInAnonymously() => + FutureOrResult signInAnonymously() => Result.tryCatchAsync( () async { final account = @@ -277,7 +277,7 @@ class AuthenticationRepositoryImpl ); @override - FutureResult verifyPasswordResetCode({required String code}) => + FutureOrResult verifyPasswordResetCode({required String code}) => Result.tryCatchAsync( () async { final response = await _authenticationRemoteDataSource @@ -288,7 +288,7 @@ class AuthenticationRepositoryImpl ); @override - FutureResult refresh() => + FutureOrResult refresh() => Result.tryCatchAsync( () async { await _authenticationRemoteDataSource.refresh(); diff --git a/packages/wyatt_authentication_bloc/lib/src/domain/repositories/authentication_repository.dart b/packages/wyatt_authentication_bloc/lib/src/domain/repositories/authentication_repository.dart index d1afeb42..b88de024 100644 --- a/packages/wyatt_authentication_bloc/lib/src/domain/repositories/authentication_repository.dart +++ b/packages/wyatt_authentication_bloc/lib/src/domain/repositories/authentication_repository.dart @@ -30,7 +30,7 @@ abstract class AuthenticationRepository extends BaseRepository { /// Throws a SignUpWithEmailAndPasswordFailureInterface if /// an exception occurs. /// {@endtemplate} - FutureResult signUp({ + FutureOrResult signUp({ required String email, required String password, }); @@ -40,21 +40,21 @@ abstract class AuthenticationRepository extends BaseRepository { /// /// Throws a SendEmailVerificationFailureInterface if an exception occurs. /// {@endtemplate} - FutureResult sendEmailVerification(); + FutureOrResult sendEmailVerification(); /// {@template send_password_reset_email} /// Sends a password reset email to the provided [email]. /// /// Throws a SendPasswordResetEmailFailureInterface if an exception occurs. /// {@endtemplate} - FutureResult sendPasswordResetEmail({required String email}); + FutureOrResult sendPasswordResetEmail({required String email}); /// {@template confirm_password_reset} /// Confirms the password reset with the provided [newPassword] and [code]. /// /// Throws a ConfirmPasswordResetFailureInterface if an exception occurs. /// {@endtemplate} - FutureResult confirmPasswordReset({ + FutureOrResult confirmPasswordReset({ required String code, required String newPassword, }); @@ -64,14 +64,14 @@ abstract class AuthenticationRepository extends BaseRepository { /// /// Throws a VerifyPasswordResetCodeFailureInterface if an exception occurs. /// {@endtemplate} - FutureResult verifyPasswordResetCode({required String code}); + FutureOrResult verifyPasswordResetCode({required String code}); /// {@template signin_anom} /// Sign in anonymously. /// /// Throws a SignInAnonymouslyFailureInterface if an exception occurs. /// {@endtemplate} - FutureResult signInAnonymously(); + FutureOrResult signInAnonymously(); /// {@template signin_pwd} /// Signs in with the provided [email] and [password]. @@ -79,7 +79,7 @@ abstract class AuthenticationRepository extends BaseRepository { /// Throws a SignInWithEmailAndPasswordFailureInterface if /// an exception occurs. /// {@endtemplate} - FutureResult signInWithEmailAndPassword({ + FutureOrResult signInWithEmailAndPassword({ required String email, required String password, }); @@ -88,9 +88,9 @@ abstract class AuthenticationRepository extends BaseRepository { /// Signs out the current user. /// It also clears the cache and the associated data. /// {@endtemplate} - FutureResult signOut(); + FutureOrResult signOut(); - FutureResult refresh(); + FutureOrResult refresh(); /// {@template stream_account} /// Stream of [AccountWrapper] which will emit the current account when @@ -99,16 +99,16 @@ abstract class AuthenticationRepository extends BaseRepository { /// Emits [AccountWrapper] with null [Account] if the user is not /// authenticated. /// {@endtemplate} - Stream>> streamAccount(); + Stream>> streamAccount(); - FutureResult getIdentityToken(); + FutureOrResult getIdentityToken(); - FutureResult getAccount(); - FutureResult setAccount(Account account); + FutureOrResult getAccount(); + FutureOrResult setAccount(Account account); - FutureResult getData(); - FutureResult setData(T? data); + FutureOrResult getData(); + FutureOrResult setData(T? data); - FutureResult> getCache(); - FutureResult destroyCache(); + FutureOrResult> getCache(); + FutureOrResult destroyCache(); }