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 58196fe7..5904d2a4 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 @@ -44,6 +44,8 @@ class AuthenticationRepositoryImpl final OnAuthChange? _onAccountChanges; + bool _pause = false; // Semaphore + AuthenticationRepositoryImpl({ required AuthenticationCacheDataSource authenticationCacheDataSource, required AuthenticationRemoteDataSource authenticationRemoteDataSource, @@ -120,6 +122,7 @@ class AuthenticationRepositoryImpl }) => Result.tryCatchAsync( () async { + _pause = true; final account = await _authenticationRemoteDataSource.signUp( email: email, password: password, @@ -135,9 +138,13 @@ class AuthenticationRepositoryImpl (error) async => error, ); } + _pause = false; return account; }, - (error) => error, + (error) { + _pause = false; + return error; + }, ); @override @@ -200,7 +207,7 @@ class AuthenticationRepositoryImpl @override Stream>> streamAccount() => _authenticationRemoteDataSource.streamAccount().map((account) async { - if (_onAccountChanges.isNotNull) { + if (_onAccountChanges.isNotNull && !_pause) { final dataResult = await _onAccountChanges!.call(account); return dataResult.map((data) => AccountWrapperModel(account, data)); }