Compare commits
	
		
			3 Commits
		
	
	
		
			a66db23ace
			...
			f0ed08bd49
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| f0ed08bd49 | |||
| 390fb81b1e | |||
| 279d451cd8 | 
@ -114,6 +114,7 @@ class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource {
 | 
				
			|||||||
      providerId: 'wyatt',
 | 
					      providerId: 'wyatt',
 | 
				
			||||||
      creationTime: creation,
 | 
					      creationTime: creation,
 | 
				
			||||||
      lastSignInTime: creation,
 | 
					      lastSignInTime: creation,
 | 
				
			||||||
 | 
					      isNewUser: creation == creation,
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    _streamAccount.add(mock);
 | 
					    _streamAccount.add(mock);
 | 
				
			||||||
    _connectedMock = _connectedMock?.copyWith(left: mock);
 | 
					    _connectedMock = _connectedMock?.copyWith(left: mock);
 | 
				
			||||||
@ -188,6 +189,7 @@ class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource {
 | 
				
			|||||||
      email: email,
 | 
					      email: email,
 | 
				
			||||||
      creationTime: creation,
 | 
					      creationTime: creation,
 | 
				
			||||||
      lastSignInTime: creation,
 | 
					      lastSignInTime: creation,
 | 
				
			||||||
 | 
					      isNewUser: creation == creation,
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    _streamAccount.add(mock);
 | 
					    _streamAccount.add(mock);
 | 
				
			||||||
    _registeredMock = Pair(mock, password);
 | 
					    _registeredMock = Pair(mock, password);
 | 
				
			||||||
 | 
				
			|||||||
@ -14,6 +14,9 @@
 | 
				
			|||||||
// You should have received a copy of the GNU General Public License
 | 
					// You should have received a copy of the GNU General Public License
 | 
				
			||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
					// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import 'dart:async';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import 'package:rxdart/rxdart.dart';
 | 
				
			||||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
 | 
					import 'package:wyatt_architecture/wyatt_architecture.dart';
 | 
				
			||||||
import 'package:wyatt_authentication_bloc/src/core/constants/form_field.dart';
 | 
					import 'package:wyatt_authentication_bloc/src/core/constants/form_field.dart';
 | 
				
			||||||
import 'package:wyatt_authentication_bloc/src/core/constants/form_name.dart';
 | 
					import 'package:wyatt_authentication_bloc/src/core/constants/form_name.dart';
 | 
				
			||||||
@ -43,6 +46,8 @@ class AuthenticationRepositoryImpl<T extends Object>
 | 
				
			|||||||
  final OnSignUpSuccess<T>? _onSignUpSuccess;
 | 
					  final OnSignUpSuccess<T>? _onSignUpSuccess;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  final OnAuthChange<T>? _onAccountChanges;
 | 
					  final OnAuthChange<T>? _onAccountChanges;
 | 
				
			||||||
 | 
					  final StreamController<FutureResult<AccountWrapper<T>>> _signUpStream =
 | 
				
			||||||
 | 
					      StreamController();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool _pause = false; // Semaphore
 | 
					  bool _pause = false; // Semaphore
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -134,7 +139,11 @@ class AuthenticationRepositoryImpl<T extends Object>
 | 
				
			|||||||
              _formRepository.accessForm(AuthFormName.signUpForm).clone(),
 | 
					              _formRepository.accessForm(AuthFormName.signUpForm).clone(),
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
            await dataResult.foldAsync(
 | 
					            await dataResult.foldAsync(
 | 
				
			||||||
              _authenticationLocalDataSource.storeData,
 | 
					              (data) async {
 | 
				
			||||||
 | 
					                await _authenticationLocalDataSource.storeData(data);
 | 
				
			||||||
 | 
					                _signUpStream
 | 
				
			||||||
 | 
					                    .add(Future.value(Ok(AccountWrapperModel(account, data))));
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
              (error) async => error,
 | 
					              (error) async => error,
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
@ -205,16 +214,21 @@ class AuthenticationRepositoryImpl<T extends Object>
 | 
				
			|||||||
      );
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
  Stream<FutureResult<AccountWrapper<T>>> streamAccount() =>
 | 
					  Stream<FutureResult<AccountWrapper<T>>> streamAccount() => MergeStream([
 | 
				
			||||||
      _authenticationRemoteDataSource.streamAccount().map((account) async {
 | 
					        _signUpStream.stream.asBroadcastStream(),
 | 
				
			||||||
        if (_onAccountChanges.isNotNull && !_pause) {
 | 
					        _authenticationRemoteDataSource.streamAccount().map((account) async {
 | 
				
			||||||
          final dataResult = await _onAccountChanges!.call(account);
 | 
					          if (_onAccountChanges.isNotNull && !_pause) {
 | 
				
			||||||
          return dataResult.map((data) => AccountWrapperModel(account, data));
 | 
					            final dataResult = await _onAccountChanges!.call(account);
 | 
				
			||||||
        }
 | 
					            return dataResult.map((data) {
 | 
				
			||||||
        return Ok<AccountWrapperModel<T>, AppException>(
 | 
					              _authenticationLocalDataSource.storeData(data);
 | 
				
			||||||
          AccountWrapperModel<T>(account, null),
 | 
					              return AccountWrapperModel(account, data);
 | 
				
			||||||
        );
 | 
					            });
 | 
				
			||||||
      });
 | 
					          }
 | 
				
			||||||
 | 
					          return Ok<AccountWrapperModel<T>, AppException>(
 | 
				
			||||||
 | 
					            AccountWrapperModel<T>(account, null),
 | 
				
			||||||
 | 
					          );
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
  FutureResult<void> confirmPasswordReset({
 | 
					  FutureResult<void> confirmPasswordReset({
 | 
				
			||||||
 | 
				
			|||||||
@ -56,6 +56,19 @@ class AuthenticationCubit<Extra> extends Cubit<AuthenticationState<Extra>> {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /// If authenticated, re-emits state with data freshly loaded from cache.
 | 
				
			||||||
 | 
					  FutureOr<void> reloadCache() async {
 | 
				
			||||||
 | 
					    if (state.status == AuthenticationStatus.authenticated) {
 | 
				
			||||||
 | 
					      final data = await _authenticationRepository.getCache();
 | 
				
			||||||
 | 
					      emit(
 | 
				
			||||||
 | 
					        data.fold(
 | 
				
			||||||
 | 
					          AuthenticationState<Extra>.authenticated,
 | 
				
			||||||
 | 
					          (error) => state,
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  FutureOr<void> signOut() {
 | 
					  FutureOr<void> signOut() {
 | 
				
			||||||
    // TODO(hpcl): maybe force unauthenticated by emitting an event
 | 
					    // TODO(hpcl): maybe force unauthenticated by emitting an event
 | 
				
			||||||
    _authenticationRepository.signOut();
 | 
					    _authenticationRepository.signOut();
 | 
				
			||||||
 | 
				
			|||||||
@ -21,6 +21,7 @@ dependencies:
 | 
				
			|||||||
  flutter_facebook_auth: ^4.3.0
 | 
					  flutter_facebook_auth: ^4.3.0
 | 
				
			||||||
  sign_in_with_apple: ^3.3.0
 | 
					  sign_in_with_apple: ^3.3.0
 | 
				
			||||||
  twitter_login: ^4.2.3
 | 
					  twitter_login: ^4.2.3
 | 
				
			||||||
 | 
					  rxdart: ^0.27.7
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  wyatt_form_bloc:
 | 
					  wyatt_form_bloc:
 | 
				
			||||||
    hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/
 | 
					    hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user