From 37e00fe9c40515fb150566686639693781d0a17f Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Mon, 12 Dec 2022 22:43:54 -0500 Subject: [PATCH 1/6] style(analysis): dart format + follows wyatt analysis 2.3.0 --- .../analysis_options.yaml | 5 +-- .../example/lib/bootstrap.dart | 6 +-- .../lib/core/constants/form_field.dart | 6 +-- .../example/lib/core/constants/form_name.dart | 6 +-- .../lib/core/utils/app_bloc_observer.dart | 6 +-- .../lib/core/utils/custom_password.dart | 6 +-- .../example/lib/main.dart | 6 +-- .../blocs/edit_profile_cubit.dart | 8 ++-- .../features/sign_in/sign_in_page.dart | 6 +-- .../sign_in/widgets/sign_in_form.dart | 6 +-- .../features/sign_up/sign_up_page.dart | 6 +-- .../sign_up/widgets/sign_up_form.dart | 6 +-- .../presentation/features/sub/sub_page.dart | 12 +++--- .../features/welcome/welcome_page.dart | 6 +-- .../example/test/widget_test.dart | 1 + .../lib/src/core/core.dart | 1 - .../src/core/enums/authentication_status.dart | 6 +-- .../lib/src/core/enums/enums.dart | 6 +-- .../lib/src/core/exceptions/exceptions.dart | 7 ++-- .../lib/src/core/utils/cryptography.dart | 39 ------------------- .../lib/src/core/utils/utils.dart | 17 -------- .../lib/src/data/data.dart | 6 +-- ...authentication_cache_data_source_impl.dart | 4 +- ...hentication_firebase_data_source_impl.dart | 6 +-- .../authentication_mock_data_source_impl.dart | 10 ++--- .../lib/src/data/models/account_model.dart | 25 ++++++------ .../data/models/account_wrapper_model.dart | 9 +++-- .../lib/src/data/models/models.dart | 6 +-- .../authentication_repository_impl.dart | 26 ++++++------- .../src/data/repositories/repositories.dart | 6 +-- .../lib/src/domain/domain.dart | 6 +-- .../lib/src/domain/entities/entities.dart | 6 +-- .../authentication_repository.dart | 6 +-- .../src/domain/repositories/repositories.dart | 6 +-- .../cubit/authentication_cubit.dart | 3 +- .../cubit/authentication_state.dart | 17 ++++---- .../cubit/email_verification_cubit.dart | 3 +- .../cubit/password_reset_cubit.dart | 7 ++-- .../cubit/password_reset_state.dart | 3 +- .../features/sign_in/cubit/sign_in_cubit.dart | 7 ++-- .../features/sign_in/cubit/sign_in_state.dart | 10 ++--- .../features/sign_up/cubit/sign_up_cubit.dart | 7 ++-- .../features/sign_up/cubit/sign_up_state.dart | 9 ++--- .../lib/src/src.dart | 6 +-- 44 files changed, 149 insertions(+), 213 deletions(-) delete mode 100644 packages/wyatt_authentication_bloc/lib/src/core/utils/cryptography.dart delete mode 100644 packages/wyatt_authentication_bloc/lib/src/core/utils/utils.dart diff --git a/packages/wyatt_authentication_bloc/analysis_options.yaml b/packages/wyatt_authentication_bloc/analysis_options.yaml index b0c6aced..82177cd5 100644 --- a/packages/wyatt_authentication_bloc/analysis_options.yaml +++ b/packages/wyatt_authentication_bloc/analysis_options.yaml @@ -1,4 +1 @@ -include: package:wyatt_analysis/analysis_options.flutter.yaml - -analyzer: - exclude: "!example/**" \ No newline at end of file +include: package:wyatt_analysis/analysis_options.flutter.yaml \ No newline at end of file diff --git a/packages/wyatt_authentication_bloc/example/lib/bootstrap.dart b/packages/wyatt_authentication_bloc/example/lib/bootstrap.dart index 4e0f4070..0b4e74c6 100644 --- a/packages/wyatt_authentication_bloc/example/lib/bootstrap.dart +++ b/packages/wyatt_authentication_bloc/example/lib/bootstrap.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/example/lib/core/constants/form_field.dart b/packages/wyatt_authentication_bloc/example/lib/core/constants/form_field.dart index 84636b9f..917131da 100644 --- a/packages/wyatt_authentication_bloc/example/lib/core/constants/form_field.dart +++ b/packages/wyatt_authentication_bloc/example/lib/core/constants/form_field.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/example/lib/core/constants/form_name.dart b/packages/wyatt_authentication_bloc/example/lib/core/constants/form_name.dart index a5ce457e..b41b7335 100644 --- a/packages/wyatt_authentication_bloc/example/lib/core/constants/form_name.dart +++ b/packages/wyatt_authentication_bloc/example/lib/core/constants/form_name.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/example/lib/core/utils/app_bloc_observer.dart b/packages/wyatt_authentication_bloc/example/lib/core/utils/app_bloc_observer.dart index 3490aee1..1a25acfd 100644 --- a/packages/wyatt_authentication_bloc/example/lib/core/utils/app_bloc_observer.dart +++ b/packages/wyatt_authentication_bloc/example/lib/core/utils/app_bloc_observer.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/example/lib/core/utils/custom_password.dart b/packages/wyatt_authentication_bloc/example/lib/core/utils/custom_password.dart index bdbb3552..d80b6d3e 100644 --- a/packages/wyatt_authentication_bloc/example/lib/core/utils/custom_password.dart +++ b/packages/wyatt_authentication_bloc/example/lib/core/utils/custom_password.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/example/lib/main.dart b/packages/wyatt_authentication_bloc/example/lib/main.dart index 0149dcb6..c41af8b6 100644 --- a/packages/wyatt_authentication_bloc/example/lib/main.dart +++ b/packages/wyatt_authentication_bloc/example/lib/main.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/example/lib/presentation/features/edit_profile/blocs/edit_profile_cubit.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_profile/blocs/edit_profile_cubit.dart index e82e2b4c..c92aa597 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_profile/blocs/edit_profile_cubit.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_profile/blocs/edit_profile_cubit.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 . @@ -71,4 +71,4 @@ class EditProfileCubit extends FormDataCubitImpl { } emit(state.copyWith(status: FormStatus.submissionSuccess)); } -} \ No newline at end of file +} diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/sign_in_page.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/sign_in_page.dart index 5d7aa1e4..19dfd0b6 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/sign_in_page.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/sign_in_page.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/example/lib/presentation/features/sign_in/widgets/sign_in_form.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/widgets/sign_in_form.dart index 865b6cec..9a8cb6ad 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/widgets/sign_in_form.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/widgets/sign_in_form.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/example/lib/presentation/features/sign_up/sign_up_page.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/sign_up_page.dart index 918f09cd..ff232348 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/sign_up_page.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/sign_up_page.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/example/lib/presentation/features/sign_up/widgets/sign_up_form.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/widgets/sign_up_form.dart index 546ec326..bb3ebceb 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/widgets/sign_up_form.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/widgets/sign_up_form.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/example/lib/presentation/features/sub/sub_page.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sub/sub_page.dart index 48a39986..a5c8a6b6 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sub/sub_page.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sub/sub_page.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 . @@ -30,10 +30,12 @@ class SubPage extends StatelessWidget { title: const Text('Sub'), actions: [ IconButton( - onPressed: () => context.read>().signOut(), + onPressed: () => + context.read>().signOut(), icon: const Icon(Icons.logout_rounded)), IconButton( - onPressed: () => context.read>().refresh(), + onPressed: () => + context.read>().refresh(), icon: const Icon(Icons.refresh)) ], ), diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/welcome/welcome_page.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/welcome/welcome_page.dart index 5080183c..10d5c0cc 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/welcome/welcome_page.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/welcome/welcome_page.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/example/test/widget_test.dart b/packages/wyatt_authentication_bloc/example/test/widget_test.dart index e69de29b..8b137891 100644 --- a/packages/wyatt_authentication_bloc/example/test/widget_test.dart +++ b/packages/wyatt_authentication_bloc/example/test/widget_test.dart @@ -0,0 +1 @@ + diff --git a/packages/wyatt_authentication_bloc/lib/src/core/core.dart b/packages/wyatt_authentication_bloc/lib/src/core/core.dart index 16b0264b..2d4165fc 100644 --- a/packages/wyatt_authentication_bloc/lib/src/core/core.dart +++ b/packages/wyatt_authentication_bloc/lib/src/core/core.dart @@ -18,4 +18,3 @@ export 'constants/form_field.dart'; export 'constants/form_name.dart'; export 'enums/enums.dart'; export 'exceptions/exceptions.dart'; -export 'utils/utils.dart'; diff --git a/packages/wyatt_authentication_bloc/lib/src/core/enums/authentication_status.dart b/packages/wyatt_authentication_bloc/lib/src/core/enums/authentication_status.dart index af10ceae..11386588 100644 --- a/packages/wyatt_authentication_bloc/lib/src/core/enums/authentication_status.dart +++ b/packages/wyatt_authentication_bloc/lib/src/core/enums/authentication_status.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/core/enums/enums.dart b/packages/wyatt_authentication_bloc/lib/src/core/enums/enums.dart index 67d107d6..db37d714 100644 --- a/packages/wyatt_authentication_bloc/lib/src/core/enums/enums.dart +++ b/packages/wyatt_authentication_bloc/lib/src/core/enums/enums.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/core/exceptions/exceptions.dart b/packages/wyatt_authentication_bloc/lib/src/core/exceptions/exceptions.dart index cfcfba68..7d418c1f 100644 --- a/packages/wyatt_authentication_bloc/lib/src/core/exceptions/exceptions.dart +++ b/packages/wyatt_authentication_bloc/lib/src/core/exceptions/exceptions.dart @@ -20,15 +20,14 @@ part 'exceptions_firebase.dart'; abstract class AuthenticationFailureInterface extends AppException implements Exception { + AuthenticationFailureInterface(this.code, this.msg); + AuthenticationFailureInterface.fromCode(this.code) + : msg = 'An unknown error occurred.'; String code; String msg; @override String get message => msg; - - AuthenticationFailureInterface(this.code, this.msg); - AuthenticationFailureInterface.fromCode(this.code) - : msg = 'An unknown error occurred.'; } /// {@template apply_action_code_failure} diff --git a/packages/wyatt_authentication_bloc/lib/src/core/utils/cryptography.dart b/packages/wyatt_authentication_bloc/lib/src/core/utils/cryptography.dart deleted file mode 100644 index f9a0b247..00000000 --- a/packages/wyatt_authentication_bloc/lib/src/core/utils/cryptography.dart +++ /dev/null @@ -1,39 +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 'dart:convert'; -import 'dart:math'; - -import 'package:crypto/crypto.dart'; - -class Cryptography { - /// Generates a cryptographically secure random nonce, to be included in a - /// credential request. - static String generateNonce([int length = 32]) { - const charset = - '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._'; - final random = Random.secure(); - return List.generate(length, (_) => charset[random.nextInt(charset.length)]) - .join(); - } - - /// Returns the sha256 hash of [input] in hex notation. - static String sha256ofString(String input) { - final bytes = utf8.encode(input); - final digest = sha256.convert(bytes); - return digest.toString(); - } -} diff --git a/packages/wyatt_authentication_bloc/lib/src/core/utils/utils.dart b/packages/wyatt_authentication_bloc/lib/src/core/utils/utils.dart deleted file mode 100644 index 81005a25..00000000 --- a/packages/wyatt_authentication_bloc/lib/src/core/utils/utils.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 'cryptography.dart'; diff --git a/packages/wyatt_authentication_bloc/lib/src/data/data.dart b/packages/wyatt_authentication_bloc/lib/src/data/data.dart index 42218c55..35d3fdd1 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/data.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/data.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/data/data_sources/local/authentication_cache_data_source_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/local/authentication_cache_data_source_impl.dart index 57b1191a..13f537bb 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/local/authentication_cache_data_source_impl.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/local/authentication_cache_data_source_impl.dart @@ -20,11 +20,11 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; class AuthenticationCacheDataSourceImpl extends AuthenticationCacheDataSource { + AuthenticationCacheDataSourceImpl(); + Account? _account; T? _data; - AuthenticationCacheDataSourceImpl(); - @override Future storeAccount(Account? account) async { _account = account; diff --git a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart index 131e160a..e24fb231 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart @@ -20,12 +20,12 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; class AuthenticationFirebaseDataSourceImpl extends AuthenticationRemoteDataSource { - final FirebaseAuth _firebaseAuth; - UserCredential? _latestCreds; - AuthenticationFirebaseDataSourceImpl({FirebaseAuth? firebaseAuth}) : _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance; + final FirebaseAuth _firebaseAuth; + UserCredential? _latestCreds; + Account _mapper(User user) => AccountModel( uid: user.uid, emailVerified: user.emailVerified, diff --git a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart index 67ef28cd..e1478f88 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart @@ -21,6 +21,11 @@ import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; import 'package:wyatt_type_utils/wyatt_type_utils.dart'; class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource { + AuthenticationMockDataSourceImpl({ + this.idToken = 'fake-id-token', + this.registeredAccounts, + }); + Pair? _connectedMock; Pair? _registeredMock; DateTime _lastSignInTime = DateTime.now(); @@ -30,11 +35,6 @@ class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource { final List>? registeredAccounts; final String idToken; - AuthenticationMockDataSourceImpl({ - this.idToken = 'fake-id-token', - this.registeredAccounts, - }); - Future _randomDelay() async { await Future.delayed( Duration(milliseconds: Random().nextInt(400) + 200), diff --git a/packages/wyatt_authentication_bloc/lib/src/data/models/account_model.dart b/packages/wyatt_authentication_bloc/lib/src/data/models/account_model.dart index d886d329..0077378b 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/models/account_model.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/models/account_model.dart @@ -72,16 +72,17 @@ class AccountModel extends Account { String? phoneNumber, String? photoURL, String? providerId, - }) => AccountModel( - uid: uid ?? this.uid, - email: email ?? this.email, - creationTime: creationTime ?? this.creationTime, - emailVerified: emailVerified ?? this.emailVerified, - isAnonymous: isAnonymous ?? this.isAnonymous, - isNewUser: isNewUser ?? this.isNewUser, - lastSignInTime: lastSignInTime ?? this.lastSignInTime, - phoneNumber: phoneNumber ?? this.phoneNumber, - photoURL: photoURL ?? this.photoURL, - providerId: providerId ?? this.providerId, - ); + }) => + AccountModel( + uid: uid ?? this.uid, + email: email ?? this.email, + creationTime: creationTime ?? this.creationTime, + emailVerified: emailVerified ?? this.emailVerified, + isAnonymous: isAnonymous ?? this.isAnonymous, + isNewUser: isNewUser ?? this.isNewUser, + lastSignInTime: lastSignInTime ?? this.lastSignInTime, + phoneNumber: phoneNumber ?? this.phoneNumber, + photoURL: photoURL ?? this.photoURL, + providerId: providerId ?? this.providerId, + ); } diff --git a/packages/wyatt_authentication_bloc/lib/src/data/models/account_wrapper_model.dart b/packages/wyatt_authentication_bloc/lib/src/data/models/account_wrapper_model.dart index e99b774e..4dae7f6b 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/models/account_wrapper_model.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/models/account_wrapper_model.dart @@ -29,8 +29,9 @@ class AccountWrapperModel extends AccountWrapper { AccountWrapperModel copyWith({ Account? account, T? data, - }) => AccountWrapperModel( - account ?? this.account, - data ?? this.data, - ); + }) => + AccountWrapperModel( + account ?? this.account, + data ?? this.data, + ); } diff --git a/packages/wyatt_authentication_bloc/lib/src/data/models/models.dart b/packages/wyatt_authentication_bloc/lib/src/data/models/models.dart index 09cc76bf..14f991fe 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/models/models.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/models/models.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/data/repositories/authentication_repository_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/repositories/authentication_repository_impl.dart index c0f2c8e1..294e1096 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 @@ -42,19 +42,6 @@ typedef OnAuthChange = FutureOrResult Function( class AuthenticationRepositoryImpl extends AuthenticationRepository { - final AuthenticationCacheDataSource _authenticationLocalDataSource; - final AuthenticationRemoteDataSource _authenticationRemoteDataSource; - - late FormRepository _formRepository; - - final OnSignUpSuccess? _onSignUpSuccess; - - final OnAuthChange? _onAccountChanges; - final StreamController>> _signUpStream = - StreamController(); - - bool _pause = false; // Semaphore - AuthenticationRepositoryImpl({ required AuthenticationCacheDataSource authenticationCacheDataSource, required AuthenticationRemoteDataSource authenticationRemoteDataSource, @@ -107,6 +94,19 @@ class AuthenticationRepositoryImpl ); } + final AuthenticationCacheDataSource _authenticationLocalDataSource; + final AuthenticationRemoteDataSource _authenticationRemoteDataSource; + + late FormRepository _formRepository; + + final OnSignUpSuccess? _onSignUpSuccess; + + final OnAuthChange? _onAccountChanges; + final StreamController>> _signUpStream = + StreamController(); + + bool _pause = false; + @override FormRepository get formRepository => _formRepository; diff --git a/packages/wyatt_authentication_bloc/lib/src/data/repositories/repositories.dart b/packages/wyatt_authentication_bloc/lib/src/data/repositories/repositories.dart index 7858c9e7..d5979688 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/repositories/repositories.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/repositories/repositories.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/domain/domain.dart b/packages/wyatt_authentication_bloc/lib/src/domain/domain.dart index 7727f7ee..6f4ec438 100644 --- a/packages/wyatt_authentication_bloc/lib/src/domain/domain.dart +++ b/packages/wyatt_authentication_bloc/lib/src/domain/domain.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/domain/entities/entities.dart b/packages/wyatt_authentication_bloc/lib/src/domain/entities/entities.dart index 8ecf9215..e9a858fe 100644 --- a/packages/wyatt_authentication_bloc/lib/src/domain/entities/entities.dart +++ b/packages/wyatt_authentication_bloc/lib/src/domain/entities/entities.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/domain/repositories/authentication_repository.dart b/packages/wyatt_authentication_bloc/lib/src/domain/repositories/authentication_repository.dart index d4b2c23b..56f1697b 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 @@ -105,8 +105,8 @@ abstract class AuthenticationRepository extends BaseRepository { }); /// {@template reauthenticate} - /// Some security-sensitive actions—such as deleting an account, - /// setting a primary email address, and changing a password—require that + /// Some security-sensitive actions—such as deleting an account, + /// setting a primary email address, and changing a password—require that /// the user has recently signed in. /// /// Throws a ReauthenticateFailureInterface if @@ -129,7 +129,7 @@ abstract class AuthenticationRepository extends BaseRepository { /// Stream of [AccountWrapper] which will emit the current account when /// the authentication state changes. /// - /// Emits [AccountWrapper] with null [Account] if the user is not + /// Emits [AccountWrapper] with null [Account] if the user is not /// authenticated. /// {@endtemplate} Stream>> streamAccount(); diff --git a/packages/wyatt_authentication_bloc/lib/src/domain/repositories/repositories.dart b/packages/wyatt_authentication_bloc/lib/src/domain/repositories/repositories.dart index 85f8ae88..8ff4eae1 100644 --- a/packages/wyatt_authentication_bloc/lib/src/domain/repositories/repositories.dart +++ b/packages/wyatt_authentication_bloc/lib/src/domain/repositories/repositories.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/authentication/cubit/authentication_cubit.dart b/packages/wyatt_authentication_bloc/lib/src/features/authentication/cubit/authentication_cubit.dart index cf648917..eab1ffbb 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 @@ -26,14 +26,13 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; part 'authentication_state.dart'; class AuthenticationCubit extends Cubit> { - final AuthenticationRepository _authenticationRepository; - AuthenticationCubit({ required AuthenticationRepository authenticationRepository, }) : _authenticationRepository = authenticationRepository, super(const AuthenticationState.unknown()) { _listenForAuthenticationChanges(); } + final AuthenticationRepository _authenticationRepository; void _listenForAuthenticationChanges() { _authenticationRepository.streamAccount().listen((accountFutureResult) { 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 bfd1e871..a5733bf2 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 @@ -17,13 +17,8 @@ part of 'authentication_cubit.dart'; class AuthenticationState extends Equatable { - final AuthenticationStatus status; - final AccountWrapper? accountWrapper; - - const AuthenticationState._({required this.status, this.accountWrapper}); - - const AuthenticationState.unknown() - : this._(status: AuthenticationStatus.unknown); + const AuthenticationState.unauthenticated() + : this._(status: AuthenticationStatus.unauthenticated); const AuthenticationState.authenticated(AccountWrapper accountWrapper) : this._( @@ -31,8 +26,12 @@ class AuthenticationState extends Equatable { accountWrapper: accountWrapper, ); - const AuthenticationState.unauthenticated() - : this._(status: AuthenticationStatus.unauthenticated); + const AuthenticationState.unknown() + : this._(status: AuthenticationStatus.unknown); + + const AuthenticationState._({required this.status, this.accountWrapper}); + final AuthenticationStatus status; + final AccountWrapper? accountWrapper; @override List get props => [status, 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 index ea829bb5..132dafd2 100644 --- 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 @@ -24,12 +24,11 @@ import 'package:wyatt_form_bloc/wyatt_form_bloc.dart'; part 'email_verification_state.dart'; class EmailVerificationCubit extends Cubit { - final AuthenticationRepository _authenticationRepository; - EmailVerificationCubit({ required AuthenticationRepository authenticationRepository, }) : _authenticationRepository = authenticationRepository, super(const EmailVerificationState()); + final AuthenticationRepository _authenticationRepository; FutureOr sendEmailVerification() async { emit(state.copyWith(status: FormStatus.submissionInProgress)); 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 index 8b793973..9ecfe309 100644 --- 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 @@ -25,10 +25,6 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; part 'password_reset_state.dart'; class PasswordResetCubit extends FormDataCubit { - final AuthenticationRepository _authenticationRepository; - FormRepository get _formRepository => - _authenticationRepository.formRepository; - PasswordResetCubit({ required AuthenticationRepository authenticationRepository, }) : _authenticationRepository = authenticationRepository, @@ -38,6 +34,9 @@ class PasswordResetCubit extends FormDataCubit { .accessForm(AuthFormName.passwordResetForm), ), ); + final AuthenticationRepository _authenticationRepository; + FormRepository get _formRepository => + _authenticationRepository.formRepository; @override String get formName => AuthFormName.passwordResetForm; 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 index 8a11957d..5c5205dd 100644 --- 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 @@ -17,13 +17,12 @@ part of 'password_reset_cubit.dart'; class PasswordResetState extends FormDataState { - Email get email => form.validatorOf(AuthFormField.email); - const PasswordResetState({ required super.form, super.status = FormStatus.pure, super.errorMessage, }); + Email get email => form.validatorOf(AuthFormField.email); PasswordResetState copyWith({ WyattForm? form, 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 5db99b5f..2ed1a9d4 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 @@ -23,10 +23,6 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; part 'sign_in_state.dart'; class SignInCubit extends FormDataCubit { - final AuthenticationRepository _authenticationRepository; - FormRepository get _formRepository => - _authenticationRepository.formRepository; - SignInCubit({ required AuthenticationRepository authenticationRepository, }) : _authenticationRepository = authenticationRepository, @@ -36,6 +32,9 @@ class SignInCubit extends FormDataCubit { .accessForm(AuthFormName.signInForm), ), ); + final AuthenticationRepository _authenticationRepository; + FormRepository get _formRepository => + _authenticationRepository.formRepository; @override String get formName => AuthFormName.signInForm; diff --git a/packages/wyatt_authentication_bloc/lib/src/features/sign_in/cubit/sign_in_state.dart b/packages/wyatt_authentication_bloc/lib/src/features/sign_in/cubit/sign_in_state.dart index 8c65fe0f..b0279886 100644 --- a/packages/wyatt_authentication_bloc/lib/src/features/sign_in/cubit/sign_in_state.dart +++ b/packages/wyatt_authentication_bloc/lib/src/features/sign_in/cubit/sign_in_state.dart @@ -17,17 +17,17 @@ part of 'sign_in_cubit.dart'; class SignInState extends FormDataState { - FormInputValidator get email => - form.validatorOf(AuthFormField.email); - FormInputValidator get password => - form.validatorOf(AuthFormField.password); - const SignInState({ required super.form, super.status = FormStatus.pure, super.errorMessage, }); + FormInputValidator get email => + form.validatorOf(AuthFormField.email); + FormInputValidator get password => + form.validatorOf(AuthFormField.password); + SignInState copyWith({ WyattForm? form, FormStatus? status, 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 38e719a1..2d7ed28b 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 @@ -25,10 +25,6 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; part 'sign_up_state.dart'; class SignUpCubit extends FormDataCubit { - final AuthenticationRepository _authenticationRepository; - FormRepository get _formRepository => - _authenticationRepository.formRepository; - SignUpCubit({ required AuthenticationRepository authenticationRepository, }) : _authenticationRepository = authenticationRepository, @@ -38,6 +34,9 @@ class SignUpCubit extends FormDataCubit { .accessForm(AuthFormName.signUpForm), ), ); + final AuthenticationRepository _authenticationRepository; + FormRepository get _formRepository => + _authenticationRepository.formRepository; @override String get formName => AuthFormName.signUpForm; diff --git a/packages/wyatt_authentication_bloc/lib/src/features/sign_up/cubit/sign_up_state.dart b/packages/wyatt_authentication_bloc/lib/src/features/sign_up/cubit/sign_up_state.dart index 8203c293..40c870c5 100644 --- a/packages/wyatt_authentication_bloc/lib/src/features/sign_up/cubit/sign_up_state.dart +++ b/packages/wyatt_authentication_bloc/lib/src/features/sign_up/cubit/sign_up_state.dart @@ -17,16 +17,15 @@ part of 'sign_up_cubit.dart'; class SignUpState extends FormDataState { - FormInputValidator get email => - form.validatorOf(AuthFormField.email); - FormInputValidator get password => - form.validatorOf(AuthFormField.password); - const SignUpState({ required super.form, super.status = FormStatus.pure, super.errorMessage, }); + FormInputValidator get email => + form.validatorOf(AuthFormField.email); + FormInputValidator get password => + form.validatorOf(AuthFormField.password); SignUpState copyWith({ WyattForm? form, diff --git a/packages/wyatt_authentication_bloc/lib/src/src.dart b/packages/wyatt_authentication_bloc/lib/src/src.dart index e5a07de0..3a660ea4 100644 --- a/packages/wyatt_authentication_bloc/lib/src/src.dart +++ b/packages/wyatt_authentication_bloc/lib/src/src.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 . From 94d573a584fe25fa42b47edf440f4f4ce7c98bc2 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Mon, 12 Dec 2022 23:14:55 -0500 Subject: [PATCH 2/6] refactor(authentication): update deps and re-export them --- .../lib/wyatt_authentication_bloc.dart | 3 +++ packages/wyatt_authentication_bloc/pubspec.yaml | 14 ++++---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/wyatt_authentication_bloc/lib/wyatt_authentication_bloc.dart b/packages/wyatt_authentication_bloc/lib/wyatt_authentication_bloc.dart index e40338b2..a010cfa4 100644 --- a/packages/wyatt_authentication_bloc/lib/wyatt_authentication_bloc.dart +++ b/packages/wyatt_authentication_bloc/lib/wyatt_authentication_bloc.dart @@ -17,4 +17,7 @@ /// An authentication library for BLoC. library wyatt_authentication_bloc; +export 'package:firebase_auth/firebase_auth.dart'; +export 'package:google_sign_in/google_sign_in.dart'; + export 'src/src.dart'; diff --git a/packages/wyatt_authentication_bloc/pubspec.yaml b/packages/wyatt_authentication_bloc/pubspec.yaml index 60b9cba1..23471ff1 100644 --- a/packages/wyatt_authentication_bloc/pubspec.yaml +++ b/packages/wyatt_authentication_bloc/pubspec.yaml @@ -10,17 +10,12 @@ environment: flutter: ">=1.17.0" dependencies: - flutter: - sdk: flutter - + flutter: { sdk: flutter } crypto: ^3.0.2 flutter_bloc: ^8.1.1 equatable: ^2.0.5 - firebase_auth: ^4.1.1 - google_sign_in: ^5.3.0 - flutter_facebook_auth: ^4.3.0 - sign_in_with_apple: ^3.3.0 - twitter_login: ^4.2.3 + firebase_auth: ^4.2.0 + google_sign_in: ^5.4.2 rxdart: ^0.27.7 wyatt_form_bloc: @@ -36,8 +31,7 @@ dependencies: version: ^0.0.4 dev_dependencies: - flutter_test: - sdk: flutter + flutter_test: { sdk: flutter } bloc_test: ^9.1.0 mocktail: ^0.3.0 From c7b241de2d5d8a7f925c15bac31b26ffc263ac46 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Mon, 12 Dec 2022 23:16:10 -0500 Subject: [PATCH 3/6] feat(authentication): add google sign_in support (closes #59) --- ...hentication_firebase_data_source_impl.dart | 34 ++++++++++++++++++- .../authentication_mock_data_source_impl.dart | 19 +++++++++++ .../authentication_repository_impl.dart | 11 ++++++ .../authentication_remote_data_source.dart | 2 ++ .../authentication_repository.dart | 7 ++++ 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart index e24fb231..78c4bf79 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import 'package:firebase_auth/firebase_auth.dart'; import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; import 'package:wyatt_type_utils/wyatt_type_utils.dart'; @@ -182,6 +181,39 @@ class AuthenticationFirebaseDataSourceImpl } } + @override + Future signInWithGoogle() async { + try { + // Trigger the authentication flow + final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn(); + + // Obtain the auth details from the request + final GoogleSignInAuthentication? googleAuth = + await googleUser?.authentication; + + // Create a new credential + final credential = GoogleAuthProvider.credential( + accessToken: googleAuth?.accessToken, + idToken: googleAuth?.idToken, + ); + + final userCredential = + await _firebaseAuth.signInWithCredential(credential); + + _latestCreds = userCredential; + final user = userCredential.user; + if (user.isNotNull) { + return _mapper(user!); + } else { + throw Exception(); // Get caught just after. + } + } on FirebaseAuthException catch (e) { + throw SignInWithGoogleFailureFirebase.fromCode(e.code); + } catch (_) { + throw SignInWithGoogleFailureFirebase(); + } + } + @override Future verifyPasswordResetCode({required String code}) async { try { diff --git a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart index e1478f88..cec578a5 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart @@ -123,6 +123,25 @@ class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource { return Future.value(mock); } + @override + Future signInWithGoogle() async { + await _randomDelay(); + final creation = DateTime.now(); + final mock = AccountModel( + uid: 'mock-id-google', + emailVerified: true, + isAnonymous: false, + providerId: 'google', + creationTime: creation, + lastSignInTime: creation, + isNewUser: creation == creation, + ); + _streamAccount.add(mock); + _connectedMock = _connectedMock?.copyWith(left: mock); + _lastSignInTime = DateTime.now(); + return Future.value(mock); + } + @override Future signInWithEmailAndPassword({ required String email, 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 294e1096..7bbc7954 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 @@ -295,6 +295,17 @@ class AuthenticationRepositoryImpl (error) => error, ); + @override + FutureOrResult signInWithGoogle() => + Result.tryCatchAsync( + () async { + final account = + await _authenticationRemoteDataSource.signInWithGoogle(); + return account; + }, + (error) => error, + ); + @override FutureOrResult verifyPasswordResetCode({required String code}) => Result.tryCatchAsync( diff --git a/packages/wyatt_authentication_bloc/lib/src/domain/data_sources/remote/authentication_remote_data_source.dart b/packages/wyatt_authentication_bloc/lib/src/domain/data_sources/remote/authentication_remote_data_source.dart index b379de92..8205bd8d 100644 --- a/packages/wyatt_authentication_bloc/lib/src/domain/data_sources/remote/authentication_remote_data_source.dart +++ b/packages/wyatt_authentication_bloc/lib/src/domain/data_sources/remote/authentication_remote_data_source.dart @@ -49,6 +49,8 @@ abstract class AuthenticationRemoteDataSource extends BaseRemoteDataSource { Future signInAnonymously(); + Future signInWithGoogle(); + Future updateEmail({required String email}); Future updatePassword({required String password}); 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 56f1697b..027c7525 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 @@ -73,6 +73,13 @@ abstract class AuthenticationRepository extends BaseRepository { /// {@endtemplate} FutureOrResult signInAnonymously(); + /// {@template signin_google} + /// Starts the Sign In with Google Flow. + /// + /// Throws a SignInWithGoogleFailureInterface if an exception occurs. + /// {@endtemplate} + FutureOrResult signInWithGoogle(); + /// {@template signin_pwd} /// Signs in with the provided [email] and [password]. /// From 197c5d54e6ce3dcd7d7fa88a8da9dfec21545859 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Mon, 12 Dec 2022 23:47:29 -0500 Subject: [PATCH 4/6] feat(authentication): add google sign in parameter in firebase data source constructor --- .../remote/authentication_firebase_data_source_impl.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart index 78c4bf79..8a16490c 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart @@ -19,10 +19,13 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; class AuthenticationFirebaseDataSourceImpl extends AuthenticationRemoteDataSource { - AuthenticationFirebaseDataSourceImpl({FirebaseAuth? firebaseAuth}) - : _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance; + AuthenticationFirebaseDataSourceImpl( + {FirebaseAuth? firebaseAuth, GoogleSignIn? googleSignIn,}) + : _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance, + _googleSignIn = googleSignIn ?? GoogleSignIn(); final FirebaseAuth _firebaseAuth; + final GoogleSignIn _googleSignIn; UserCredential? _latestCreds; Account _mapper(User user) => AccountModel( @@ -185,7 +188,7 @@ class AuthenticationFirebaseDataSourceImpl Future signInWithGoogle() async { try { // Trigger the authentication flow - final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn(); + final GoogleSignInAccount? googleUser = await _googleSignIn.signIn(); // Obtain the auth details from the request final GoogleSignInAuthentication? googleAuth = From 1a3631f691a593bd7922b91f4a37b0f8608cbe52 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Tue, 13 Dec 2022 00:36:20 -0500 Subject: [PATCH 5/6] feat(authentication): add google sign in in signIn cubit --- .../example/.gitignore | 4 +- .../example/.vscode/launch.json | 11 ++- .../example/ios/Podfile.lock | 89 ++++++------------- .../example/ios/Runner/Info.plist | 11 +++ .../example/ios/firebase_app_id_file.json | 6 +- .../example/lib/bootstrap.dart | 44 +++++++++ .../lib/core/dependency_injection/get_it.dart | 48 +++++----- .../example/lib/firebase_options.dart | 65 ++++++++++++++ .../example/lib/main.dart | 1 + .../example/lib/main_firebase.dart | 23 +++++ .../sign_in/widgets/sign_in_form.dart | 18 ++++ .../authentication_mock_data_source_impl.dart | 4 +- .../features/sign_in/cubit/sign_in_cubit.dart | 20 +++++ 13 files changed, 251 insertions(+), 93 deletions(-) create mode 100644 packages/wyatt_authentication_bloc/example/lib/firebase_options.dart create mode 100644 packages/wyatt_authentication_bloc/example/lib/main_firebase.dart diff --git a/packages/wyatt_authentication_bloc/example/.gitignore b/packages/wyatt_authentication_bloc/example/.gitignore index f0edd542..891ead31 100644 --- a/packages/wyatt_authentication_bloc/example/.gitignore +++ b/packages/wyatt_authentication_bloc/example/.gitignore @@ -44,6 +44,4 @@ app.*.map.json # Android Studio will place build artifacts here /android/app/debug /android/app/profile -/android/app/release - -firebase_options.dart \ No newline at end of file +/android/app/release \ No newline at end of file diff --git a/packages/wyatt_authentication_bloc/example/.vscode/launch.json b/packages/wyatt_authentication_bloc/example/.vscode/launch.json index 61fa495d..11233cfe 100644 --- a/packages/wyatt_authentication_bloc/example/.vscode/launch.json +++ b/packages/wyatt_authentication_bloc/example/.vscode/launch.json @@ -4,7 +4,7 @@ * ----- * File: launch.json * Created Date: 19/08/2022 15:12:25 - * Last Modified: 19/08/2022 15:22:02 + * Last Modified: Tue Dec 13 2022 * ----- * Copyright (c) 2022 */ @@ -15,11 +15,18 @@ "version": "0.2.0", "configurations": [ { - "name": "example_router", + "name": "Mock", "request": "launch", "type": "dart", "program": "lib/main.dart", "flutterMode": "debug" + }, + { + "name": "Firebase", + "request": "launch", + "type": "dart", + "program": "lib/main_firebase.dart", + "flutterMode": "debug" } ] } \ No newline at end of file diff --git a/packages/wyatt_authentication_bloc/example/ios/Podfile.lock b/packages/wyatt_authentication_bloc/example/ios/Podfile.lock index 1a4d1789..bc6894a5 100644 --- a/packages/wyatt_authentication_bloc/example/ios/Podfile.lock +++ b/packages/wyatt_authentication_bloc/example/ios/Podfile.lock @@ -5,41 +5,30 @@ PODS: - AppAuth/Core (1.6.0) - AppAuth/ExternalUserAgent (1.6.0): - AppAuth/Core - - FBAEMKit (14.1.0): - - FBSDKCoreKit_Basics (= 14.1.0) - - FBSDKCoreKit (14.1.0): - - FBAEMKit (= 14.1.0) - - FBSDKCoreKit_Basics (= 14.1.0) - - FBSDKCoreKit_Basics (14.1.0) - - FBSDKLoginKit (14.1.0): - - FBSDKCoreKit (= 14.1.0) - - Firebase/Auth (10.0.0): + - Firebase/Auth (10.3.0): - Firebase/CoreOnly - - FirebaseAuth (~> 10.0.0) - - Firebase/CoreOnly (10.0.0): - - FirebaseCore (= 10.0.0) - - firebase_auth (4.1.1): - - Firebase/Auth (= 10.0.0) + - FirebaseAuth (~> 10.3.0) + - Firebase/CoreOnly (10.3.0): + - FirebaseCore (= 10.3.0) + - firebase_auth (4.2.0): + - Firebase/Auth (= 10.3.0) - firebase_core - Flutter - - firebase_core (2.1.1): - - Firebase/CoreOnly (= 10.0.0) + - firebase_core (2.4.0): + - Firebase/CoreOnly (= 10.3.0) - Flutter - - FirebaseAuth (10.0.0): + - FirebaseAuth (10.3.0): - FirebaseCore (~> 10.0) - GoogleUtilities/AppDelegateSwizzler (~> 7.8) - GoogleUtilities/Environment (~> 7.8) - - GTMSessionFetcher/Core (~> 2.1) - - FirebaseCore (10.0.0): + - GTMSessionFetcher/Core (< 4.0, >= 2.1) + - FirebaseCore (10.3.0): - FirebaseCoreInternal (~> 10.0) - GoogleUtilities/Environment (~> 7.8) - GoogleUtilities/Logger (~> 7.8) - - FirebaseCoreInternal (10.1.0): + - FirebaseCoreInternal (10.3.0): - "GoogleUtilities/NSData+zlib (~> 7.8)" - Flutter (1.0.0) - - flutter_facebook_auth (4.4.1): - - FBSDKLoginKit (= 14.1.0) - - Flutter - google_sign_in_ios (0.0.1): - Flutter - GoogleSignIn (~> 6.2) @@ -47,47 +36,36 @@ PODS: - AppAuth (~> 1.5) - GTMAppAuth (~> 1.3) - GTMSessionFetcher/Core (< 3.0, >= 1.1) - - GoogleUtilities/AppDelegateSwizzler (7.8.0): + - GoogleUtilities/AppDelegateSwizzler (7.10.0): - GoogleUtilities/Environment - GoogleUtilities/Logger - GoogleUtilities/Network - - GoogleUtilities/Environment (7.8.0): + - GoogleUtilities/Environment (7.10.0): - PromisesObjC (< 3.0, >= 1.2) - - GoogleUtilities/Logger (7.8.0): + - GoogleUtilities/Logger (7.10.0): - GoogleUtilities/Environment - - GoogleUtilities/Network (7.8.0): + - GoogleUtilities/Network (7.10.0): - GoogleUtilities/Logger - "GoogleUtilities/NSData+zlib" - GoogleUtilities/Reachability - - "GoogleUtilities/NSData+zlib (7.8.0)" - - GoogleUtilities/Reachability (7.8.0): + - "GoogleUtilities/NSData+zlib (7.10.0)" + - GoogleUtilities/Reachability (7.10.0): - GoogleUtilities/Logger - GTMAppAuth (1.3.1): - AppAuth/Core (~> 1.6) - GTMSessionFetcher/Core (< 3.0, >= 1.5) - - GTMSessionFetcher/Core (2.1.0) + - GTMSessionFetcher/Core (2.3.0) - PromisesObjC (2.1.1) - - sign_in_with_apple (0.0.1): - - Flutter - - twitter_login (0.0.1): - - Flutter DEPENDENCIES: - firebase_auth (from `.symlinks/plugins/firebase_auth/ios`) - firebase_core (from `.symlinks/plugins/firebase_core/ios`) - Flutter (from `Flutter`) - - flutter_facebook_auth (from `.symlinks/plugins/flutter_facebook_auth/ios`) - google_sign_in_ios (from `.symlinks/plugins/google_sign_in_ios/ios`) - - sign_in_with_apple (from `.symlinks/plugins/sign_in_with_apple/ios`) - - twitter_login (from `.symlinks/plugins/twitter_login/ios`) SPEC REPOS: trunk: - AppAuth - - FBAEMKit - - FBSDKCoreKit - - FBSDKCoreKit_Basics - - FBSDKLoginKit - Firebase - FirebaseAuth - FirebaseCore @@ -105,37 +83,24 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/firebase_core/ios" Flutter: :path: Flutter - flutter_facebook_auth: - :path: ".symlinks/plugins/flutter_facebook_auth/ios" google_sign_in_ios: :path: ".symlinks/plugins/google_sign_in_ios/ios" - sign_in_with_apple: - :path: ".symlinks/plugins/sign_in_with_apple/ios" - twitter_login: - :path: ".symlinks/plugins/twitter_login/ios" SPEC CHECKSUMS: AppAuth: 8fca6b5563a5baef2c04bee27538025e4ceb2add - FBAEMKit: a899515e45476027f73aef377b5cffadcd56ca3a - FBSDKCoreKit: 24f8bc8d3b5b2a8c5c656a1329492a12e8efa792 - FBSDKCoreKit_Basics: 6e578c9bdc7aa1365dbbbde633c9ebb536bcaa98 - FBSDKLoginKit: 787de205d524c3a4b17d527916f1d066e4361660 - Firebase: 1b810f3d0c0532e27a48f1961f8c0400a668a2cf - firebase_auth: dd33e93fce72a1c72040f7380dacf06e89db5705 - firebase_core: 5c0bb0ca7d0e70480a68a6e9ad9bf55d1edd5305 - FirebaseAuth: 493382cf533cc45e2862b00e9aa4cfe4c98daf71 - FirebaseCore: 97f48a3a567a72b8d4daa0f03c3aadb78df4e995 - FirebaseCoreInternal: 96d75228e10fd369564da51bd898414eb0f54df5 + Firebase: f92fc551ead69c94168d36c2b26188263860acd9 + firebase_auth: 579a0dc15451491cc83fccaa5102296635f24938 + firebase_core: 6f2f753e316765799d88568232ed59e300ff53db + FirebaseAuth: 0e415d29d846c1dce2fb641e46f35e9888d9bec6 + FirebaseCore: 988754646ab3bd4bdcb740f1bfe26b9f6c0d5f2a + FirebaseCoreInternal: 29b76f784d607df8b2a1259d73c3f04f1210137b Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 - flutter_facebook_auth: 361ac7a57263ebf327f26089507ead0d66558ee8 google_sign_in_ios: 4f85eb9f937450765c8573bb85fd8cd6a5af675c GoogleSignIn: 5651ce3a61e56ca864160e79b484cd9ed3f49b7a - GoogleUtilities: 1d20a6ad97ef46f67bbdec158ce00563a671ebb7 + GoogleUtilities: bad72cb363809015b1f7f19beb1f1cd23c589f95 GTMAppAuth: 0ff230db599948a9ad7470ca667337803b3fc4dd - GTMSessionFetcher: ffbb25ec00ebcb5201adab0a56d808f6f1902d9f + GTMSessionFetcher: 3a63d75eecd6aa32c2fc79f578064e1214dfdec2 PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb - sign_in_with_apple: f3bf75217ea4c2c8b91823f225d70230119b8440 - twitter_login: 2794db69b7640681171b17b3c2c84ad9dfb4a57f PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3 diff --git a/packages/wyatt_authentication_bloc/example/ios/Runner/Info.plist b/packages/wyatt_authentication_bloc/example/ios/Runner/Info.plist index e2987027..e8c1f83a 100644 --- a/packages/wyatt_authentication_bloc/example/ios/Runner/Info.plist +++ b/packages/wyatt_authentication_bloc/example/ios/Runner/Info.plist @@ -28,6 +28,17 @@ LaunchScreen UIMainStoryboardFile Main + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLSchemes + + com.googleusercontent.apps.405351917235-2jv4ff02kovoim58f8d6d0rsa14apgkj + + + UISupportedInterfaceOrientations UIInterfaceOrientationPortrait diff --git a/packages/wyatt_authentication_bloc/example/ios/firebase_app_id_file.json b/packages/wyatt_authentication_bloc/example/ios/firebase_app_id_file.json index 17445d1d..2a145385 100644 --- a/packages/wyatt_authentication_bloc/example/ios/firebase_app_id_file.json +++ b/packages/wyatt_authentication_bloc/example/ios/firebase_app_id_file.json @@ -1,7 +1,7 @@ { "file_generated_by": "FlutterFire CLI", "purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory", - "GOOGLE_APP_ID": "1:136771801992:ios:bcdca68d2b7d227097203d", - "FIREBASE_PROJECT_ID": "tchat-beta", - "GCM_SENDER_ID": "136771801992" + "GOOGLE_APP_ID": "1:405351917235:ios:869f0ad8ace08db899f2c6", + "FIREBASE_PROJECT_ID": "meerabel-dev", + "GCM_SENDER_ID": "405351917235" } \ No newline at end of file diff --git a/packages/wyatt_authentication_bloc/example/lib/bootstrap.dart b/packages/wyatt_authentication_bloc/example/lib/bootstrap.dart index 0b4e74c6..0f64001a 100644 --- a/packages/wyatt_authentication_bloc/example/lib/bootstrap.dart +++ b/packages/wyatt_authentication_bloc/example/lib/bootstrap.dart @@ -18,9 +18,47 @@ import 'dart:async'; import 'package:example_router/core/dependency_injection/get_it.dart'; import 'package:example_router/core/utils/app_bloc_observer.dart'; +import 'package:example_router/firebase_options.dart'; +import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +class MockSettings { + static MockSettings? _instance; + + /// Data source mode + late bool enable = false; + + MockSettings._(this.enable); + + factory MockSettings.enable() { + _instance ??= MockSettings._(true); + if (_instance!.enable != true) { + throw Exception('Mock already initialized in: ${_instance!.enable}'); + } + return _instance!; + } + + factory MockSettings.disable() { + _instance ??= MockSettings._(false); + if (_instance!.enable != false) { + throw Exception('Mock already initialized in: ${_instance!.enable}'); + } + return _instance!; + } + + static bool isEnable() { + if (_instance == null) { + throw Exception('MockSettings not initialized!'); + } + return _instance!.enable == true; + } + + static bool isDisable() { + return !isEnable(); + } +} + Future bootstrap(FutureOr Function() builder) async { await runZonedGuarded( () async { @@ -30,6 +68,12 @@ Future bootstrap(FutureOr Function() builder) async { FlutterError.onError = (details) { debugPrint(details.toString()); }; + + if (MockSettings.isDisable()) { + await Firebase.initializeApp( + options: DefaultFirebaseOptions.currentPlatform, + ); + } await GetItInitializer.init(); runApp(await builder()); diff --git a/packages/wyatt_authentication_bloc/example/lib/core/dependency_injection/get_it.dart b/packages/wyatt_authentication_bloc/example/lib/core/dependency_injection/get_it.dart index a665ccb7..29cd0a73 100644 --- a/packages/wyatt_authentication_bloc/example/lib/core/dependency_injection/get_it.dart +++ b/packages/wyatt_authentication_bloc/example/lib/core/dependency_injection/get_it.dart @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'package:example_router/bootstrap.dart'; +import 'package:example_router/firebase_options.dart'; import 'package:get_it/get_it.dart'; import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; import 'package:wyatt_type_utils/wyatt_type_utils.dart'; @@ -24,28 +26,32 @@ abstract class GetItInitializer { static Future init() async { getIt ..registerLazySingleton( - () => AuthenticationMockDataSourceImpl(registeredAccounts: [ - Pair( - AccountModel( - uid: '1', - emailVerified: true, - isAnonymous: false, - providerId: 'wyatt', - email: 'toto@test.fr', + MockSettings.isEnable() + ? () => AuthenticationMockDataSourceImpl(registeredAccounts: [ + Pair( + AccountModel( + uid: '1', + emailVerified: true, + isAnonymous: false, + providerId: 'wyatt', + email: 'toto@test.fr', + ), + 'toto1234', + ), + Pair( + AccountModel( + uid: '2', + emailVerified: false, + isAnonymous: false, + providerId: 'wyatt', + email: 'tata@test.fr', + ), + 'tata1234', + ), + ]) + : () => AuthenticationFirebaseDataSourceImpl( + googleSignIn: GoogleSignIn(clientId: DefaultFirebaseOptions.ios.iosClientId) ), - 'toto1234', - ), - Pair( - AccountModel( - uid: '2', - emailVerified: false, - isAnonymous: false, - providerId: 'wyatt', - email: 'tata@test.fr', - ), - 'tata1234', - ), - ]), ) ..registerLazySingleton>( () => AuthenticationCacheDataSourceImpl(), diff --git a/packages/wyatt_authentication_bloc/example/lib/firebase_options.dart b/packages/wyatt_authentication_bloc/example/lib/firebase_options.dart new file mode 100644 index 00000000..95cbbdfb --- /dev/null +++ b/packages/wyatt_authentication_bloc/example/lib/firebase_options.dart @@ -0,0 +1,65 @@ +// File generated by FlutterFire CLI. +// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members +import 'package:firebase_core/firebase_core.dart' show FirebaseOptions; +import 'package:flutter/foundation.dart' + show defaultTargetPlatform, kIsWeb, TargetPlatform; + +/// Default [FirebaseOptions] for use with your Firebase apps. +/// +/// Example: +/// ```dart +/// import 'firebase_options.dart'; +/// // ... +/// await Firebase.initializeApp( +/// options: DefaultFirebaseOptions.currentPlatform, +/// ); +/// ``` +class DefaultFirebaseOptions { + static FirebaseOptions get currentPlatform { + if (kIsWeb) { + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for web - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + } + switch (defaultTargetPlatform) { + case TargetPlatform.android: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for android - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.iOS: + return ios; + case TargetPlatform.macOS: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for macos - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.windows: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for windows - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.linux: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for linux - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + default: + throw UnsupportedError( + 'DefaultFirebaseOptions are not supported for this platform.', + ); + } + } + + static const FirebaseOptions ios = FirebaseOptions( + apiKey: 'AIzaSyDDmtf0KN7Xw12_pqUsxoBfAxMuvCMmMmk', + appId: '1:405351917235:ios:869f0ad8ace08db899f2c6', + messagingSenderId: '405351917235', + projectId: 'meerabel-dev', + storageBucket: 'meerabel-dev.appspot.com', + androidClientId: '405351917235-4g1dh3475tq6t1sa2qoh7ol60nf4ta05.apps.googleusercontent.com', + iosClientId: '405351917235-2jv4ff02kovoim58f8d6d0rsa14apgkj.apps.googleusercontent.com', + iosBundleId: 'com.example.exampleRouter', + ); +} diff --git a/packages/wyatt_authentication_bloc/example/lib/main.dart b/packages/wyatt_authentication_bloc/example/lib/main.dart index c41af8b6..ddc4cb52 100644 --- a/packages/wyatt_authentication_bloc/example/lib/main.dart +++ b/packages/wyatt_authentication_bloc/example/lib/main.dart @@ -18,5 +18,6 @@ import 'package:example_router/bootstrap.dart'; import 'package:example_router/presentation/features/app/app.dart'; void main() { + MockSettings.enable(); bootstrap(App.new); } diff --git a/packages/wyatt_authentication_bloc/example/lib/main_firebase.dart b/packages/wyatt_authentication_bloc/example/lib/main_firebase.dart new file mode 100644 index 00000000..d53f0050 --- /dev/null +++ b/packages/wyatt_authentication_bloc/example/lib/main_firebase.dart @@ -0,0 +1,23 @@ +// 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:example_router/bootstrap.dart'; +import 'package:example_router/presentation/features/app/app.dart'; + +void main() { + MockSettings.disable(); + bootstrap(App.new); +} diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/widgets/sign_in_form.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/widgets/sign_in_form.dart index 9a8cb6ad..f0e1dfa9 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/widgets/sign_in_form.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/widgets/sign_in_form.dart @@ -94,6 +94,22 @@ class _SignInAnonymouslyButton extends StatelessWidget { } } +class _SignInWithGoogleButton extends StatelessWidget { + @override + Widget build(BuildContext context) { + return SubmitBuilder>( + builder: ((context, cubit, status) { + return status.isSubmissionInProgress + ? const CircularProgressIndicator() + : ElevatedButton( + onPressed: () => cubit.signInWithGoogle(), + child: const Text('Sign in Google'), + ); + }), + ); + } +} + class SignInForm extends StatelessWidget { const SignInForm({Key? key}) : super(key: key); @@ -116,6 +132,8 @@ class SignInForm extends StatelessWidget { _SignInButton(), const SizedBox(height: 16), _SignInAnonymouslyButton(), + const SizedBox(height: 16), + _SignInWithGoogleButton(), ], ), ), diff --git a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart index cec578a5..4d4fed65 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart @@ -112,7 +112,7 @@ class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource { uid: 'mock-id-anom', emailVerified: false, isAnonymous: true, - providerId: 'wyatt', + providerId: 'wyatt-studio.fr', creationTime: creation, lastSignInTime: creation, isNewUser: creation == creation, @@ -131,7 +131,7 @@ class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource { uid: 'mock-id-google', emailVerified: true, isAnonymous: false, - providerId: 'google', + providerId: 'google.com', creationTime: creation, lastSignInTime: creation, isNewUser: creation == creation, 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 2ed1a9d4..91262ce3 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 @@ -205,4 +205,24 @@ class SignInCubit extends FormDataCubit { ), ); } + + FutureOr signInWithGoogle() async { + if (state.status.isSubmissionInProgress) { + return; + } + // TODO(wyatt): maybe emit new state (to not carry an old errorMessage) + emit(state.copyWith(status: FormStatus.submissionInProgress)); + + final uid = await _authenticationRepository.signInWithGoogle(); + + emit( + uid.fold( + (value) => state.copyWith(status: FormStatus.submissionSuccess), + (error) => state.copyWith( + errorMessage: error.message, + status: FormStatus.submissionFailure, + ), + ), + ); + } } From 5f52b2fc3ddbb770da46521375074d45b47a6155 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Tue, 13 Dec 2022 17:00:26 -0500 Subject: [PATCH 6/6] refactor(authentication): use fromFirebaseUser factory to parse user --- .../lib/core/dependency_injection/get_it.dart | 4 +- .../example/lib/firebase_options.dart | 6 +- .../lib/src/core/exceptions/exceptions.dart | 8 +- .../core/exceptions/exceptions_firebase.dart | 7 ++ ...authentication_cache_data_source_impl.dart | 1 - ...hentication_firebase_data_source_impl.dart | 73 +++++-------------- .../authentication_mock_data_source_impl.dart | 1 - .../data/models/account_model_firebase.dart | 55 ++++++++++++++ .../cubit/authentication_cubit.dart | 1 - .../cubit/authentication_state.dart | 1 - .../features/sign_up/cubit/sign_up_state.dart | 1 - 11 files changed, 92 insertions(+), 66 deletions(-) create mode 100644 packages/wyatt_authentication_bloc/lib/src/data/models/account_model_firebase.dart diff --git a/packages/wyatt_authentication_bloc/example/lib/core/dependency_injection/get_it.dart b/packages/wyatt_authentication_bloc/example/lib/core/dependency_injection/get_it.dart index 29cd0a73..d1cb33ab 100644 --- a/packages/wyatt_authentication_bloc/example/lib/core/dependency_injection/get_it.dart +++ b/packages/wyatt_authentication_bloc/example/lib/core/dependency_injection/get_it.dart @@ -50,8 +50,8 @@ abstract class GetItInitializer { ), ]) : () => AuthenticationFirebaseDataSourceImpl( - googleSignIn: GoogleSignIn(clientId: DefaultFirebaseOptions.ios.iosClientId) - ), + googleSignIn: GoogleSignIn( + clientId: DefaultFirebaseOptions.ios.iosClientId)), ) ..registerLazySingleton>( () => AuthenticationCacheDataSourceImpl(), diff --git a/packages/wyatt_authentication_bloc/example/lib/firebase_options.dart b/packages/wyatt_authentication_bloc/example/lib/firebase_options.dart index 95cbbdfb..10987933 100644 --- a/packages/wyatt_authentication_bloc/example/lib/firebase_options.dart +++ b/packages/wyatt_authentication_bloc/example/lib/firebase_options.dart @@ -58,8 +58,10 @@ class DefaultFirebaseOptions { messagingSenderId: '405351917235', projectId: 'meerabel-dev', storageBucket: 'meerabel-dev.appspot.com', - androidClientId: '405351917235-4g1dh3475tq6t1sa2qoh7ol60nf4ta05.apps.googleusercontent.com', - iosClientId: '405351917235-2jv4ff02kovoim58f8d6d0rsa14apgkj.apps.googleusercontent.com', + androidClientId: + '405351917235-4g1dh3475tq6t1sa2qoh7ol60nf4ta05.apps.googleusercontent.com', + iosClientId: + '405351917235-2jv4ff02kovoim58f8d6d0rsa14apgkj.apps.googleusercontent.com', iosBundleId: 'com.example.exampleRouter', ); } diff --git a/packages/wyatt_authentication_bloc/lib/src/core/exceptions/exceptions.dart b/packages/wyatt_authentication_bloc/lib/src/core/exceptions/exceptions.dart index ba71af54..f60c915e 100644 --- a/packages/wyatt_authentication_bloc/lib/src/core/exceptions/exceptions.dart +++ b/packages/wyatt_authentication_bloc/lib/src/core/exceptions/exceptions.dart @@ -20,7 +20,6 @@ part 'exceptions_firebase.dart'; abstract class AuthenticationFailureInterface extends AppException implements Exception { - AuthenticationFailureInterface(this.code, this.msg); AuthenticationFailureInterface.fromCode(this.code) : msg = 'An unknown error occurred.'; @@ -277,3 +276,10 @@ abstract class UpdatePasswordFailureInterface UpdatePasswordFailureInterface.fromCode(super.code) : super.fromCode(); } + +abstract class ModelParsingFailureInterface + extends AuthenticationFailureInterface { + ModelParsingFailureInterface(super.code, super.msg); + + ModelParsingFailureInterface.fromCode(super.code) : super.fromCode(); +} diff --git a/packages/wyatt_authentication_bloc/lib/src/core/exceptions/exceptions_firebase.dart b/packages/wyatt_authentication_bloc/lib/src/core/exceptions/exceptions_firebase.dart index c36dcbd0..58e3c409 100644 --- a/packages/wyatt_authentication_bloc/lib/src/core/exceptions/exceptions_firebase.dart +++ b/packages/wyatt_authentication_bloc/lib/src/core/exceptions/exceptions_firebase.dart @@ -349,3 +349,10 @@ class UpdatePasswordFailureFirebase extends UpdatePasswordFailureInterface { } } } + +class ModelParsingFailureFirebase extends ModelParsingFailureInterface { + ModelParsingFailureFirebase([String? code, String? msg]) + : super(code ?? 'unknown', msg ?? 'An unknown error occurred.'); + + ModelParsingFailureFirebase.fromCode(super.code) : super.fromCode(); +} diff --git a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/local/authentication_cache_data_source_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/local/authentication_cache_data_source_impl.dart index b224575a..abcb673a 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/local/authentication_cache_data_source_impl.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/local/authentication_cache_data_source_impl.dart @@ -20,7 +20,6 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; class AuthenticationCacheDataSourceImpl extends AuthenticationCacheDataSource { - AuthenticationCacheDataSourceImpl(); Account? _account; T? _data; diff --git a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart index 8a16490c..8a4ce432 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_firebase_data_source_impl.dart @@ -14,36 +14,22 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'package:wyatt_authentication_bloc/src/data/models/account_model_firebase.dart'; import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; import 'package:wyatt_type_utils/wyatt_type_utils.dart'; class AuthenticationFirebaseDataSourceImpl extends AuthenticationRemoteDataSource { - AuthenticationFirebaseDataSourceImpl( - {FirebaseAuth? firebaseAuth, GoogleSignIn? googleSignIn,}) - : _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance, + AuthenticationFirebaseDataSourceImpl({ + FirebaseAuth? firebaseAuth, + GoogleSignIn? googleSignIn, + }) : _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance, _googleSignIn = googleSignIn ?? GoogleSignIn(); final FirebaseAuth _firebaseAuth; final GoogleSignIn _googleSignIn; UserCredential? _latestCreds; - Account _mapper(User user) => AccountModel( - uid: user.uid, - emailVerified: user.emailVerified, - isAnonymous: user.isAnonymous, - providerId: user.providerData.first.providerId, - creationTime: user.metadata.creationTime, - lastSignInTime: user.metadata.lastSignInTime, - isNewUser: (user.metadata.creationTime != null && - user.metadata.lastSignInTime != null) - ? user.metadata.lastSignInTime! == user.metadata.creationTime! - : null, - email: user.email, - phoneNumber: user.phoneNumber, - photoURL: user.photoURL, - ); - @override Future signInWithEmailAndPassword({ required String email, @@ -56,11 +42,7 @@ class AuthenticationFirebaseDataSourceImpl ); _latestCreds = userCredential; final user = userCredential.user; - if (user.isNotNull) { - return _mapper(user!); - } else { - throw Exception(); // Get caught just after. - } + return AccountModelFirebase.fromFirebaseUser(user); } on FirebaseAuthException catch (e) { throw SignInWithEmailAndPasswordFailureFirebase.fromCode(e.code); } catch (_) { @@ -82,11 +64,7 @@ class AuthenticationFirebaseDataSourceImpl ); _latestCreds = userCredential; final user = userCredential.user; - if (user.isNotNull) { - return _mapper(user!); - } else { - throw Exception(); // Get caught just after. - } + return AccountModelFirebase.fromFirebaseUser(user); } on FirebaseAuthException catch (e) { throw SignUpWithEmailAndPasswordFailureFirebase.fromCode(e.code); } catch (_) { @@ -123,8 +101,11 @@ class AuthenticationFirebaseDataSourceImpl @override Stream streamAccount() => _firebaseAuth.userChanges().map((user) { - final Account? account = (user.isNotNull) ? _mapper(user!) : null; - return account; + try { + return AccountModelFirebase.fromFirebaseUser(user); + } on FirebaseAuthException { + return null; + } }); @override @@ -172,11 +153,7 @@ class AuthenticationFirebaseDataSourceImpl final userCredential = await _firebaseAuth.signInAnonymously(); _latestCreds = userCredential; final user = userCredential.user; - if (user.isNotNull) { - return _mapper(user!); - } else { - throw Exception(); // Get caught just after. - } + return AccountModelFirebase.fromFirebaseUser(user); } on FirebaseAuthException catch (e) { throw SignInAnonymouslyFailureFirebase.fromCode(e.code); } catch (_) { @@ -205,11 +182,7 @@ class AuthenticationFirebaseDataSourceImpl _latestCreds = userCredential; final user = userCredential.user; - if (user.isNotNull) { - return _mapper(user!); - } else { - throw Exception(); // Get caught just after. - } + return AccountModelFirebase.fromFirebaseUser(user); } on FirebaseAuthException catch (e) { throw SignInWithGoogleFailureFirebase.fromCode(e.code); } catch (_) { @@ -250,11 +223,7 @@ class AuthenticationFirebaseDataSourceImpl throw Exception(); // Get caught just after. } final user = _firebaseAuth.currentUser; - if (user.isNotNull) { - return _mapper(user!); - } else { - throw Exception(); // Get caught just after. - } + return AccountModelFirebase.fromFirebaseUser(user); } on FirebaseAuthException catch (e) { throw ReauthenticateFailureFirebase.fromCode(e.code); } catch (_) { @@ -267,11 +236,7 @@ class AuthenticationFirebaseDataSourceImpl try { await _firebaseAuth.currentUser!.updateEmail(email); final user = _firebaseAuth.currentUser; - if (user.isNotNull) { - return _mapper(user!); - } else { - throw Exception(); // Get caught just after. - } + return AccountModelFirebase.fromFirebaseUser(user); } on FirebaseAuthException catch (e) { throw UpdateEmailFailureFirebase.fromCode(e.code); } catch (_) { @@ -284,11 +249,7 @@ class AuthenticationFirebaseDataSourceImpl try { await _firebaseAuth.currentUser!.updatePassword(password); final user = _firebaseAuth.currentUser; - if (user.isNotNull) { - return _mapper(user!); - } else { - throw Exception(); // Get caught just after. - } + return AccountModelFirebase.fromFirebaseUser(user); } on FirebaseAuthException catch (e) { throw UpdatePasswordFailureFirebase.fromCode(e.code); } catch (_) { diff --git a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart index 0c686ac6..1ee3a767 100644 --- a/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart +++ b/packages/wyatt_authentication_bloc/lib/src/data/data_sources/remote/authentication_mock_data_source_impl.dart @@ -21,7 +21,6 @@ import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; import 'package:wyatt_type_utils/wyatt_type_utils.dart'; class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource { - AuthenticationMockDataSourceImpl({ this.idToken = 'fake-id-token', this.registeredAccounts, diff --git a/packages/wyatt_authentication_bloc/lib/src/data/models/account_model_firebase.dart b/packages/wyatt_authentication_bloc/lib/src/data/models/account_model_firebase.dart new file mode 100644 index 00000000..22313043 --- /dev/null +++ b/packages/wyatt_authentication_bloc/lib/src/data/models/account_model_firebase.dart @@ -0,0 +1,55 @@ +// ignore_for_file: public_member_api_docs, sort_constructors_first +// 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:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; + +class AccountModelFirebase extends AccountModel { + AccountModelFirebase._({ + required super.uid, + required super.emailVerified, + required super.isAnonymous, + required super.providerId, + super.lastSignInTime, + super.creationTime, + super.isNewUser, + super.email, + super.phoneNumber, + super.photoURL, + }); + + factory AccountModelFirebase.fromFirebaseUser(User? user) { + if (user != null) { + return AccountModelFirebase._( + uid: user.uid, + emailVerified: user.emailVerified, + isAnonymous: user.isAnonymous, + providerId: user.providerData.first.providerId, + creationTime: user.metadata.creationTime, + lastSignInTime: user.metadata.lastSignInTime, + isNewUser: (user.metadata.creationTime != null && + user.metadata.lastSignInTime != null) + ? user.metadata.lastSignInTime! == user.metadata.creationTime! + : null, + email: user.email, + phoneNumber: user.phoneNumber, + photoURL: user.photoURL, + ); + } else { + throw ModelParsingFailureFirebase('null-user', 'User cannot be null!'); + } + } +} 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 5db96018..eab1ffbb 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 @@ -26,7 +26,6 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart'; part 'authentication_state.dart'; class AuthenticationCubit extends Cubit> { - AuthenticationCubit({ required AuthenticationRepository authenticationRepository, }) : _authenticationRepository = authenticationRepository, 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 b68660a0..a5733bf2 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 @@ -17,7 +17,6 @@ part of 'authentication_cubit.dart'; class AuthenticationState extends Equatable { - const AuthenticationState.unauthenticated() : this._(status: AuthenticationStatus.unauthenticated); diff --git a/packages/wyatt_authentication_bloc/lib/src/features/sign_up/cubit/sign_up_state.dart b/packages/wyatt_authentication_bloc/lib/src/features/sign_up/cubit/sign_up_state.dart index 414e9916..40c870c5 100644 --- a/packages/wyatt_authentication_bloc/lib/src/features/sign_up/cubit/sign_up_state.dart +++ b/packages/wyatt_authentication_bloc/lib/src/features/sign_up/cubit/sign_up_state.dart @@ -17,7 +17,6 @@ part of 'sign_up_cubit.dart'; class SignUpState extends FormDataState { - const SignUpState({ required super.form, super.status = FormStatus.pure,