diff --git a/packages/wyatt_authentication_bloc/lib/src/features/authentication/builder/authentication_builder.dart b/packages/wyatt_authentication_bloc/lib/src/features/authentication/builder/authentication_builder.dart index f10c88c3..4a19e6a9 100644 --- a/packages/wyatt_authentication_bloc/lib/src/features/authentication/builder/authentication_builder.dart +++ b/packages/wyatt_authentication_bloc/lib/src/features/authentication/builder/authentication_builder.dart @@ -16,7 +16,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:wyatt_authentication_bloc/src/domain/entities/user.dart'; +import 'package:wyatt_authentication_bloc/src/core/enums/authentication_status.dart'; +import 'package:wyatt_authentication_bloc/src/domain/entities/account_wrapper.dart'; import 'package:wyatt_authentication_bloc/src/features/authentication/cubit/authentication_cubit.dart'; class AuthenticationBuilder extends StatelessWidget { @@ -29,8 +30,7 @@ class AuthenticationBuilder extends StatelessWidget { final Widget Function( BuildContext context, - User user, - Extra? extra, + AccountWrapper accountWrapper, ) authenticated; final Widget Function(BuildContext context) unauthenticated; final Widget Function(BuildContext context) unknown; @@ -40,8 +40,8 @@ class AuthenticationBuilder extends StatelessWidget { BlocBuilder, AuthenticationState>( builder: (context, state) { if (state.status == AuthenticationStatus.authenticated) { - if (state.user != null) { - return authenticated(context, state.user!, state.extra); + if (state.accountWrapper != null) { + return authenticated(context, state.accountWrapper!); } else { return unauthenticated(context); } diff --git a/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_cubit.dart b/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_cubit.dart index 95ae5a59..af9cb0b0 100644 --- a/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_cubit.dart +++ b/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_cubit.dart @@ -18,83 +18,46 @@ import 'dart:async'; import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:wyatt_authentication_bloc/src/core/enum/auth_cubit_status.dart'; -import 'package:wyatt_authentication_bloc/src/domain/entities/user.dart'; +import 'package:wyatt_authentication_bloc/src/core/enums/authentication_status.dart'; +import 'package:wyatt_authentication_bloc/src/domain/entities/account_wrapper.dart'; import 'package:wyatt_authentication_bloc/src/domain/repositories/authentication_repository.dart'; +import 'package:wyatt_type_utils/wyatt_type_utils.dart'; part 'authentication_state.dart'; class AuthenticationCubit extends Cubit> { - final AuthenticationRepository _authenticationRepository; - late final StreamSubscription _statusSubscription; - - StreamSubscription? _userSubscription; - - final Future Function(User user)? _onAuthSuccess; + final AuthenticationRepository _authenticationRepository; AuthenticationCubit({ - required AuthenticationRepository authenticationRepository, - Future Function(User user)? onAuthSuccess, + required AuthenticationRepository authenticationRepository, }) : _authenticationRepository = authenticationRepository, - _onAuthSuccess = onAuthSuccess, super(const AuthenticationState.unknown()) { - _subscribeStatus(); + _listenForAuthenticationChanges(); } - Future get status async => - _authenticationRepository.cubitStatus.last; - - void _subscribeStatus() { - try { - _statusSubscription = _authenticationRepository.cubitStatus.listen( - (status) { - switch (status) { - case AuthCubitStatus.started: - start(); - break; - case AuthCubitStatus.stoped: - stop(); - break; + void _listenForAuthenticationChanges() { + _authenticationRepository.streamAccount().listen((accountFutureResult) { + accountFutureResult.fold( + (value) { + if (value.account.isNotNull) { + emit(AuthenticationState.authenticated(value)); + return; } + _authenticationRepository.destroyCache(); + emit(const AuthenticationState.unauthenticated()); + return; + }, + (error) { + _authenticationRepository.destroyCache(); + emit(const AuthenticationState.unauthenticated()); + return; }, ); - } catch (_) {} + }); } - Future init() async { - final firstUser = await _authenticationRepository.user.first; - _authenticationRepository.changeCubitStatus(AuthCubitStatus.started); - return changeStatus(firstUser); - } - - bool start() { - _userSubscription = _authenticationRepository.user.listen(changeStatus); - return true; - } - - bool stop() { - _userSubscription?.cancel(); - return true; - } - - Future changeStatus(User user) async { - if (user.isNotEmpty) { - final Extra? extra = await _onAuthSuccess?.call(user); - emit(AuthenticationState.authenticated(user, extra)); - } else { - _authenticationRepository.changeCubitStatus(AuthCubitStatus.stoped); - emit(const AuthenticationState.unauthenticated()); - } - } - - void logOut() { - unawaited(_authenticationRepository.signOut()); - } - - @override - Future close() { - _userSubscription?.cancel(); - _statusSubscription.cancel(); - return super.close(); + FutureOr signOut() { + // TODO(hpcl): maybe force unauthenticated by emitting an event + _authenticationRepository.signOut(); } } diff --git a/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_state.dart b/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_state.dart index d01fdfb7..0a3bc98e 100644 --- a/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_state.dart +++ b/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_state.dart @@ -16,42 +16,28 @@ part of 'authentication_cubit.dart'; -enum AuthenticationStatus { - unknown, - authenticated, - unauthenticated, -} - class AuthenticationState extends Equatable { final AuthenticationStatus status; - final User? user; - final Extra? extra; + final AccountWrapper? accountWrapper; - const AuthenticationState._({ - required this.status, - this.user, - this.extra, - }); + const AuthenticationState._({required this.status, this.accountWrapper}); const AuthenticationState.unknown() : this._(status: AuthenticationStatus.unknown); - const AuthenticationState.authenticated( - User user, - Extra? extra, - ) : this._( + const AuthenticationState.authenticated(AccountWrapper accountWrapper) + : this._( status: AuthenticationStatus.authenticated, - user: user, - extra: extra, + accountWrapper: accountWrapper, ); const AuthenticationState.unauthenticated() : this._(status: AuthenticationStatus.unauthenticated); @override - List get props => [status, user, extra]; + List get props => [status]; @override String toString() => - 'AuthenticationState(status: $status, user: $user, extra: $extra)'; + 'AuthenticationState(status: $status, accountWrapper: $accountWrapper)'; } diff --git a/packages/wyatt_authentication_bloc/lib/src/features/email_verification/cubit/email_verification_cubit.dart b/packages/wyatt_authentication_bloc/lib/src/features/email_verification/cubit/email_verification_cubit.dart deleted file mode 100644 index 2ef607a0..00000000 --- a/packages/wyatt_authentication_bloc/lib/src/features/email_verification/cubit/email_verification_cubit.dart +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2022 WYATT GROUP -// Please see the AUTHORS file for details. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -import 'package:equatable/equatable.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:wyatt_authentication_bloc/src/core/exceptions/exceptions.dart'; -import 'package:wyatt_authentication_bloc/src/domain/repositories/authentication_repository.dart'; -import 'package:wyatt_form_bloc/wyatt_form_bloc.dart' show FormStatus; - -part 'email_verification_state.dart'; - -class EmailVerificationCubit extends Cubit { - final AuthenticationRepository _authenticationRepository; - - EmailVerificationCubit({ - required AuthenticationRepository authenticationRepository, - }) : _authenticationRepository = authenticationRepository, - super(const EmailVerificationState()); - - Future sendEmailVerification() async { - emit(state.copyWith(status: FormStatus.submissionInProgress)); - try { - await _authenticationRepository.sendEmailVerification(); - emit(state.copyWith(status: FormStatus.submissionSuccess)); - } on SendEmailVerificationFailureInterface catch (e) { - emit( - state.copyWith( - errorMessage: e.message, - status: FormStatus.submissionFailure, - ), - ); - } catch (_) { - emit(state.copyWith(status: FormStatus.submissionFailure)); - } - } - - Future checkEmailVerification() async { - emit(state.copyWith(status: FormStatus.submissionInProgress)); - try { - await _authenticationRepository.refresh(); - emit( - state.copyWith( - isVerified: _authenticationRepository.currentUser.emailVerified, - status: FormStatus.submissionSuccess, - ), - ); - } on RefreshFailureInterface catch (e) { - emit( - state.copyWith( - errorMessage: e.message, - status: FormStatus.submissionFailure, - ), - ); - } catch (_) { - emit(state.copyWith(status: FormStatus.submissionFailure)); - } - } -} diff --git a/packages/wyatt_authentication_bloc/lib/src/features/email_verification/cubit/email_verification_state.dart b/packages/wyatt_authentication_bloc/lib/src/features/email_verification/cubit/email_verification_state.dart deleted file mode 100644 index f05f2caf..00000000 --- a/packages/wyatt_authentication_bloc/lib/src/features/email_verification/cubit/email_verification_state.dart +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2022 WYATT GROUP -// Please see the AUTHORS file for details. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -part of 'email_verification_cubit.dart'; - -class EmailVerificationState extends Equatable { - final bool isVerified; - final FormStatus status; - final String? errorMessage; - - const EmailVerificationState({ - this.isVerified = false, - this.status = FormStatus.pure, - this.errorMessage, - }); - - EmailVerificationState copyWith({ - bool? isVerified, - FormStatus? status, - String? errorMessage, - }) => EmailVerificationState( - isVerified: isVerified ?? this.isVerified, - status: status ?? this.status, - errorMessage: errorMessage ?? this.errorMessage, - ); - - @override - List get props => [isVerified, status]; -} diff --git a/packages/wyatt_authentication_bloc/lib/src/features/email_verification/email_verification.dart b/packages/wyatt_authentication_bloc/lib/src/features/features.dart similarity index 85% rename from packages/wyatt_authentication_bloc/lib/src/features/email_verification/email_verification.dart rename to packages/wyatt_authentication_bloc/lib/src/features/features.dart index 59beab8e..e1b478e9 100644 --- a/packages/wyatt_authentication_bloc/lib/src/features/email_verification/email_verification.dart +++ b/packages/wyatt_authentication_bloc/lib/src/features/features.dart @@ -1,17 +1,19 @@ // Copyright (C) 2022 WYATT GROUP // Please see the AUTHORS file for details. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program. If not, see . -export 'cubit/email_verification_cubit.dart'; +export 'authentication/authentication.dart'; +export 'sign_in/sign_in.dart'; +export 'sign_up/sign_up.dart'; diff --git a/packages/wyatt_authentication_bloc/lib/src/features/password_reset/cubit/password_reset_cubit.dart b/packages/wyatt_authentication_bloc/lib/src/features/password_reset/cubit/password_reset_cubit.dart deleted file mode 100644 index 66ab6545..00000000 --- a/packages/wyatt_authentication_bloc/lib/src/features/password_reset/cubit/password_reset_cubit.dart +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2022 WYATT GROUP -// Please see the AUTHORS file for details. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -import 'package:equatable/equatable.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:wyatt_authentication_bloc/src/core/exceptions/exceptions.dart'; -import 'package:wyatt_authentication_bloc/src/domain/repositories/authentication_repository.dart'; -import 'package:wyatt_form_bloc/wyatt_form_bloc.dart'; - -part 'password_reset_state.dart'; - -class PasswordResetCubit extends Cubit { - final AuthenticationRepository _authenticationRepository; - - final FormValidator _validationStrategy; - - PasswordResetCubit({ - required AuthenticationRepository authenticationRepository, - FormValidator validationStrategy = const EveryInputValidator(), - }) : _authenticationRepository = authenticationRepository, - _validationStrategy = validationStrategy, - super(const PasswordResetState()); - - void emailChanged(String value) { - final Email email = Email.dirty(value); - emit( - state.copyWith( - email: email, - status: _validationStrategy.rawValidate([email]), - ), - ); - } - - Future sendPasswordResetEmail() async { - if (!state.status.isValidated) { - return; - } - emit(state.copyWith(status: FormStatus.submissionInProgress)); - try { - await _authenticationRepository.sendPasswordResetEmail( - email: state.email.value, - ); - emit(state.copyWith(status: FormStatus.submissionSuccess)); - } on SendPasswordResetEmailFailureInterface catch (e) { - emit( - state.copyWith( - errorMessage: e.message, - status: FormStatus.submissionFailure, - ), - ); - } catch (_) { - emit(state.copyWith(status: FormStatus.submissionFailure)); - } - } -} diff --git a/packages/wyatt_authentication_bloc/lib/src/features/password_reset/cubit/password_reset_state.dart b/packages/wyatt_authentication_bloc/lib/src/features/password_reset/cubit/password_reset_state.dart deleted file mode 100644 index e8100c8e..00000000 --- a/packages/wyatt_authentication_bloc/lib/src/features/password_reset/cubit/password_reset_state.dart +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2022 WYATT GROUP -// Please see the AUTHORS file for details. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -part of 'password_reset_cubit.dart'; - -class PasswordResetState extends Equatable { - final Email email; - final FormStatus status; - final String? errorMessage; - - const PasswordResetState({ - this.email = const Email.pure(), - this.status = FormStatus.pure, - this.errorMessage, - }); - - PasswordResetState copyWith({ - Email? email, - FormStatus? status, - String? errorMessage, - }) => PasswordResetState( - email: email ?? this.email, - status: status ?? this.status, - errorMessage: errorMessage ?? this.errorMessage, - ); - - @override - List get props => [email, status]; -} diff --git a/packages/wyatt_authentication_bloc/lib/src/features/password_reset/password_reset.dart b/packages/wyatt_authentication_bloc/lib/src/features/password_reset/password_reset.dart deleted file mode 100644 index 43919e02..00000000 --- a/packages/wyatt_authentication_bloc/lib/src/features/password_reset/password_reset.dart +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2022 WYATT GROUP -// Please see the AUTHORS file for details. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -export 'cubit/password_reset_cubit.dart'; diff --git a/packages/wyatt_authentication_bloc/lib/src/features/sign_in/cubit/sign_in_cubit.dart b/packages/wyatt_authentication_bloc/lib/src/features/sign_in/cubit/sign_in_cubit.dart index 2891dc57..531c94b4 100644 --- a/packages/wyatt_authentication_bloc/lib/src/features/sign_in/cubit/sign_in_cubit.dart +++ b/packages/wyatt_authentication_bloc/lib/src/features/sign_in/cubit/sign_in_cubit.dart @@ -16,20 +16,18 @@ import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:wyatt_authentication_bloc/src/core/enum/auth_cubit_status.dart'; -import 'package:wyatt_authentication_bloc/src/core/exceptions/exceptions.dart'; import 'package:wyatt_authentication_bloc/src/domain/repositories/authentication_repository.dart'; import 'package:wyatt_form_bloc/wyatt_form_bloc.dart'; part 'sign_in_state.dart'; -class SignInCubit extends Cubit { - final AuthenticationRepository _authenticationRepository; +class SignInCubit extends Cubit { + final AuthenticationRepository _authenticationRepository; final FormValidator _validationStrategy; SignInCubit({ - required AuthenticationRepository authenticationRepository, + required AuthenticationRepository authenticationRepository, FormValidator validationStrategy = const EveryInputValidator(), }) : _authenticationRepository = authenticationRepository, _validationStrategy = validationStrategy, @@ -55,71 +53,26 @@ class SignInCubit extends Cubit { ); } - Future signInAnonymously() async { - if (state.status.isSubmissionInProgress) { - return; - } - - emit(state.copyWith(status: FormStatus.submissionInProgress)); - try { - await _authenticationRepository.signInAnonymously(); - _authenticationRepository.changeCubitStatus(AuthCubitStatus.started); - emit(state.copyWith(status: FormStatus.submissionSuccess)); - } on SignInAnonymouslyFailureInterface catch (e) { - emit( - state.copyWith( - errorMessage: e.message, - status: FormStatus.submissionFailure, - ), - ); - } catch (_) { - emit(state.copyWith(status: FormStatus.submissionFailure)); - } - } - - Future signInWithGoogle() async { - if (state.status.isSubmissionInProgress) { - return; - } - - emit(state.copyWith(status: FormStatus.submissionInProgress)); - try { - await _authenticationRepository.signInWithGoogle(); - _authenticationRepository.changeCubitStatus(AuthCubitStatus.started); - emit(state.copyWith(status: FormStatus.submissionSuccess)); - } on SignInWithGoogleFailureInterface catch (e) { - emit( - state.copyWith( - errorMessage: e.message, - status: FormStatus.submissionFailure, - ), - ); - } catch (_) { - emit(state.copyWith(status: FormStatus.submissionFailure)); - } - } - Future signInWithEmailAndPassword() async { if (!state.status.isValidated) { return; } + emit(state.copyWith(status: FormStatus.submissionInProgress)); - try { - await _authenticationRepository.signInWithEmailAndPassword( - email: state.email.value, - password: state.password.value, - ); - _authenticationRepository.changeCubitStatus(AuthCubitStatus.started); - emit(state.copyWith(status: FormStatus.submissionSuccess)); - } on SignInWithEmailAndPasswordFailureInterface catch (e) { - emit( - state.copyWith( - errorMessage: e.message, + + final uid = await _authenticationRepository.signInWithEmailAndPassword( + email: state.email.value, + password: state.password.value, + ); + + emit( + uid.fold( + (value) => state.copyWith(status: FormStatus.submissionSuccess), + (error) => state.copyWith( + errorMessage: error.message, status: FormStatus.submissionFailure, ), - ); - } catch (_) { - emit(state.copyWith(status: FormStatus.submissionFailure)); - } + ), + ); } } diff --git a/packages/wyatt_authentication_bloc/lib/src/features/sign_in/sign_in.dart b/packages/wyatt_authentication_bloc/lib/src/features/sign_in/sign_in.dart index 77700ab6..ea803529 100644 --- a/packages/wyatt_authentication_bloc/lib/src/features/sign_in/sign_in.dart +++ b/packages/wyatt_authentication_bloc/lib/src/features/sign_in/sign_in.dart @@ -1,16 +1,16 @@ // Copyright (C) 2022 WYATT GROUP // Please see the AUTHORS file for details. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program. If not, see . diff --git a/packages/wyatt_authentication_bloc/lib/src/features/sign_up/cubit/sign_up_cubit.dart b/packages/wyatt_authentication_bloc/lib/src/features/sign_up/cubit/sign_up_cubit.dart index 3e79b7a8..5d338498 100644 --- a/packages/wyatt_authentication_bloc/lib/src/features/sign_up/cubit/sign_up_cubit.dart +++ b/packages/wyatt_authentication_bloc/lib/src/features/sign_up/cubit/sign_up_cubit.dart @@ -17,28 +17,22 @@ import 'dart:async'; import 'package:equatable/equatable.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:wyatt_authentication_bloc/src/core/enum/auth_cubit_status.dart'; -import 'package:wyatt_authentication_bloc/src/core/exceptions/exceptions.dart'; import 'package:wyatt_authentication_bloc/src/domain/repositories/authentication_repository.dart'; import 'package:wyatt_form_bloc/wyatt_form_bloc.dart'; part 'sign_up_state.dart'; -class SignUpCubit extends Cubit { - final AuthenticationRepository _authenticationRepository; +class SignUpCubit extends Cubit { + final AuthenticationRepository _authenticationRepository; - final Future Function(SignUpState state, String? uid)? _onSignUpSuccess; final FormValidator _validationStrategy; SignUpCubit({ - required AuthenticationRepository authenticationRepository, + required AuthenticationRepository authenticationRepository, required FormData formData, FormValidator validationStrategy = const EveryInputValidator(), - Future Function(SignUpState state, String? uid)? onSignUpSuccess, }) : _authenticationRepository = authenticationRepository, - _onSignUpSuccess = onSignUpSuccess, _validationStrategy = validationStrategy, super(SignUpState(data: formData)); @@ -144,24 +138,20 @@ class SignUpCubit extends Cubit { return; } emit(state.copyWith(status: FormStatus.submissionInProgress)); - try { - final uid = await _authenticationRepository.signUp( - email: state.email.value, - password: state.password.value, - ); - await _onSignUpSuccess?.call(state, uid); - _authenticationRepository.changeCubitStatus(AuthCubitStatus.started); - emit(state.copyWith(status: FormStatus.submissionSuccess)); - } on SignUpWithEmailAndPasswordFailureInterface catch (e) { - emit( - state.copyWith( - errorMessage: e.message, + + final uid = await _authenticationRepository.signUp( + email: state.email.value, + password: state.password.value, + ); + + emit( + uid.fold( + (value) => state.copyWith(status: FormStatus.submissionSuccess), + (error) => state.copyWith( + errorMessage: error.message, status: FormStatus.submissionFailure, ), - ); - } catch (e) { - debugPrint(e.toString()); - emit(state.copyWith(status: FormStatus.submissionFailure)); - } + ), + ); } } diff --git a/packages/wyatt_authentication_bloc/lib/src/features/sign_up/sign_up.dart b/packages/wyatt_authentication_bloc/lib/src/features/sign_up/sign_up.dart index 798c644d..d03bdb75 100644 --- a/packages/wyatt_authentication_bloc/lib/src/features/sign_up/sign_up.dart +++ b/packages/wyatt_authentication_bloc/lib/src/features/sign_up/sign_up.dart @@ -1,16 +1,16 @@ // Copyright (C) 2022 WYATT GROUP // Please see the AUTHORS file for details. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program. If not, see . diff --git a/packages/wyatt_authentication_bloc/lib/src/src.dart b/packages/wyatt_authentication_bloc/lib/src/src.dart index 62ba6ef9..e5a07de0 100644 --- a/packages/wyatt_authentication_bloc/lib/src/src.dart +++ b/packages/wyatt_authentication_bloc/lib/src/src.dart @@ -1,30 +1,20 @@ // Copyright (C) 2022 WYATT GROUP // Please see the AUTHORS file for details. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program. If not, see . -export 'core/enum/auth_cubit_status.dart'; -export 'core/exceptions/exceptions.dart'; -export 'core/exceptions/exceptions_firebase.dart'; -export 'core/extensions/firebase_auth_user_x.dart'; -export 'core/utils/cryptography.dart'; -export 'data/models/user_firebase.dart'; -export 'data/repositories/authentication_repository_firebase.dart'; -export 'domain/entities/user.dart'; -export 'domain/repositories/authentication_repository.dart'; -export 'features/authentication/authentication.dart'; -export 'features/email_verification/email_verification.dart'; -export 'features/password_reset/password_reset.dart'; -export 'features/sign_in/sign_in.dart'; -export 'features/sign_up/sign_up.dart'; +export 'core/core.dart'; +export 'data/data.dart'; +export 'domain/domain.dart'; +export 'features/features.dart';