diff --git a/packages/wyatt_authentication_bloc/example/.firebaserc b/packages/wyatt_authentication_bloc/example/.firebaserc new file mode 100644 index 00000000..54e8fe84 --- /dev/null +++ b/packages/wyatt_authentication_bloc/example/.firebaserc @@ -0,0 +1,5 @@ +{ + "projects": { + "default": "tchat-beta" + } +} diff --git a/packages/wyatt_authentication_bloc/example/firebase.json b/packages/wyatt_authentication_bloc/example/firebase.json new file mode 100644 index 00000000..cdcf8e18 --- /dev/null +++ b/packages/wyatt_authentication_bloc/example/firebase.json @@ -0,0 +1,13 @@ +{ + "emulators": { + "auth": { + "port": 9099 + }, + "firestore": { + "port": 8080 + }, + "ui": { + "enabled": true + } + } +} 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 2a145385..17445d1d 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:405351917235:ios:869f0ad8ace08db899f2c6", - "FIREBASE_PROJECT_ID": "meerabel-dev", - "GCM_SENDER_ID": "405351917235" + "GOOGLE_APP_ID": "1:136771801992:ios:bcdca68d2b7d227097203d", + "FIREBASE_PROJECT_ID": "tchat-beta", + "GCM_SENDER_ID": "136771801992" } \ 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 0f64001a..8cf305fd 100644 --- a/packages/wyatt_authentication_bloc/example/lib/bootstrap.dart +++ b/packages/wyatt_authentication_bloc/example/lib/bootstrap.dart @@ -22,6 +22,7 @@ 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'; +import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; class MockSettings { static MockSettings? _instance; @@ -73,6 +74,7 @@ Future bootstrap(FutureOr Function() builder) async { await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); + await FirebaseAuth.instance.useAuthEmulator('localhost', 9099); } await GetItInitializer.init(); 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 d1cb33ab..2528fa87 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,6 +50,7 @@ abstract class GetItInitializer { ), ]) : () => AuthenticationFirebaseDataSourceImpl( + firebaseAuth: FirebaseAuth.instance, googleSignIn: GoogleSignIn( clientId: DefaultFirebaseOptions.ios.iosClientId)), ) diff --git a/packages/wyatt_authentication_bloc/example/lib/firebase_options.dart b/packages/wyatt_authentication_bloc/example/lib/firebase_options.dart index 10987933..dcf7c17e 100644 --- a/packages/wyatt_authentication_bloc/example/lib/firebase_options.dart +++ b/packages/wyatt_authentication_bloc/example/lib/firebase_options.dart @@ -24,10 +24,7 @@ class DefaultFirebaseOptions { } switch (defaultTargetPlatform) { case TargetPlatform.android: - throw UnsupportedError( - 'DefaultFirebaseOptions have not been configured for android - ' - 'you can reconfigure this by running the FlutterFire CLI again.', - ); + return android; case TargetPlatform.iOS: return ios; case TargetPlatform.macOS: @@ -52,16 +49,24 @@ class DefaultFirebaseOptions { } } + static const FirebaseOptions android = FirebaseOptions( + apiKey: 'AIzaSyAYS14uXupkS158Q5QAFP1864UrUN_yDSk', + appId: '1:136771801992:android:ac3cfeb99fb0763e97203d', + messagingSenderId: '136771801992', + projectId: 'tchat-beta', + databaseURL: 'https://tchat-beta.firebaseio.com', + storageBucket: 'tchat-beta.appspot.com', + ); + 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', + apiKey: 'AIzaSyCDbbhjbFrQwLXuIANdJzjkDk8uOETnn7w', + appId: '1:136771801992:ios:bcdca68d2b7d227097203d', + messagingSenderId: '136771801992', + projectId: 'tchat-beta', + databaseURL: 'https://tchat-beta.firebaseio.com', + storageBucket: 'tchat-beta.appspot.com', + androidClientId: '136771801992-n2pq8oqutvrqj58e05hbavvc7n1jdfjb.apps.googleusercontent.com', + iosClientId: '136771801992-p629tpo9bk3hcm2955s5ahivdla57ln9.apps.googleusercontent.com', iosBundleId: 'com.example.exampleRouter', ); } diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/app/app.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/app/app.dart index 99d1d999..db27b90e 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/app/app.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/app/app.dart @@ -22,6 +22,7 @@ import 'package:example_router/core/dependency_injection/get_it.dart'; import 'package:example_router/core/routes/router.dart'; import 'package:example_router/core/utils/custom_password.dart'; import 'package:example_router/core/utils/forms.dart'; +import 'package:example_router/presentation/features/sign_up/blocs/custom_sign_up_cubit.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; @@ -30,30 +31,20 @@ import 'package:wyatt_form_bloc/wyatt_form_bloc.dart'; import 'package:wyatt_type_utils/wyatt_type_utils.dart'; import 'package:wyatt_architecture/wyatt_architecture.dart'; -FutureOrResult onSignUpSuccess( - AuthenticationRepository repo, - Account? account, - WyattForm form, -) async { - const id = -1; - final confirmedPassword = - form.valueOf(AppFormField.confirmedPassword); - - debugPrint( - 'onSignUpSuccess: $account, generatedId: $id, extraFormData: $confirmedPassword'); - return const Ok(id); -} - FutureOrResult onAccountChanges( AuthenticationRepository repo, - Account? account, + AuthChangeEvent? authEvent, ) async { - final id = Random().nextInt(1000); - final token = - await repo.getIdentityToken().fold((value) => value, (error) => 'null'); + if (authEvent is SignInAuthChangeEvent || authEvent is RefreshAuthChangeEvent) { + final id = Random().nextInt(1000); + final token = + await repo.getIdentityToken().fold((value) => value, (error) => 'null'); - debugPrint('onAccountChanges: $account, token: $token, generatedId: $id'); - return Ok(id); + debugPrint('onAccountChanges: ${authEvent?.account}, type: ${authEvent.runtimeType}, token: $token, generatedId: $id'); + return Ok(id); + } else { + return Err(ClientException('Not supported auth change logic')); + } } class App extends StatelessWidget { @@ -61,7 +52,6 @@ class App extends StatelessWidget { AuthenticationRepositoryImpl( authenticationCacheDataSource: getIt>(), authenticationRemoteDataSource: getIt(), - onSignUpSuccess: onSignUpSuccess, onAuthChange: onAccountChanges, customPasswordValidator: const CustomPassword.pure(), extraSignUpInputs: [ @@ -127,7 +117,7 @@ class App extends StatelessWidget { value: authenticationCubit, ), BlocProvider>( - create: (_) => SignUpCubit( + create: (_) => CustomSignUpCubit( authenticationRepository: authenticationRepository, ), ), diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/blocs/custom_sign_up_cubit.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/blocs/custom_sign_up_cubit.dart new file mode 100644 index 00000000..7e5f1e6d --- /dev/null +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/blocs/custom_sign_up_cubit.dart @@ -0,0 +1,46 @@ +// 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:async'; + +import 'package:example_router/core/constants/form_field.dart'; +import 'package:flutter/foundation.dart'; +import 'package:wyatt_architecture/wyatt_architecture.dart'; +import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; +import 'package:wyatt_form_bloc/wyatt_form_bloc.dart'; +import 'package:wyatt_type_utils/wyatt_type_utils.dart'; + +class CustomSignUpCubit extends SignUpCubit{ + CustomSignUpCubit({ + required super.authenticationRepository, + }); + + @override + FutureOrResult onSignUpWithEmailAndPassword( + Result result, WyattForm form) async { + if (result.isOk) { + await Future.delayed(const Duration(seconds: 3)); + const id = -1; + final confirmedPassword = + form.valueOf(AppFormField.confirmedPassword); + + debugPrint( + 'onSignUpSuccess: ${result.ok}, generatedId: $id, intFormData: $confirmedPassword'); + return const Ok(id); + } + return const Ok(null); + } +} 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 bb3ebceb..a4f44a48 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 @@ -106,7 +106,7 @@ class _SignUpButton extends StatelessWidget { return status.isSubmissionInProgress ? const CircularProgressIndicator() : ElevatedButton( - onPressed: status.isValidated ? () => cubit.submit() : null, + onPressed: status.isValidated ? () => cubit.signUpWithEmailPassword() : null, child: const Text('Sign up'), ); }),