docs(authentication): update example
This commit is contained in:
		
							parent
							
								
									97c14c7a99
								
							
						
					
					
						commit
						c005c3dc43
					
				
							
								
								
									
										5
									
								
								packages/wyatt_authentication_bloc/example/.firebaserc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								packages/wyatt_authentication_bloc/example/.firebaserc
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | |||||||
|  | { | ||||||
|  |   "projects": { | ||||||
|  |     "default": "tchat-beta" | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										13
									
								
								packages/wyatt_authentication_bloc/example/firebase.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								packages/wyatt_authentication_bloc/example/firebase.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | |||||||
|  | { | ||||||
|  |   "emulators": { | ||||||
|  |     "auth": { | ||||||
|  |       "port": 9099 | ||||||
|  |     }, | ||||||
|  |     "firestore": { | ||||||
|  |       "port": 8080 | ||||||
|  |     }, | ||||||
|  |     "ui": { | ||||||
|  |       "enabled": true | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -1,7 +1,7 @@ | |||||||
| { | { | ||||||
|   "file_generated_by": "FlutterFire CLI", |   "file_generated_by": "FlutterFire CLI", | ||||||
|   "purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory", |   "purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory", | ||||||
|   "GOOGLE_APP_ID": "1:405351917235:ios:869f0ad8ace08db899f2c6", |   "GOOGLE_APP_ID": "1:136771801992:ios:bcdca68d2b7d227097203d", | ||||||
|   "FIREBASE_PROJECT_ID": "meerabel-dev", |   "FIREBASE_PROJECT_ID": "tchat-beta", | ||||||
|   "GCM_SENDER_ID": "405351917235" |   "GCM_SENDER_ID": "136771801992" | ||||||
| } | } | ||||||
| @ -22,6 +22,7 @@ import 'package:example_router/firebase_options.dart'; | |||||||
| import 'package:firebase_core/firebase_core.dart'; | import 'package:firebase_core/firebase_core.dart'; | ||||||
| import 'package:flutter/widgets.dart'; | import 'package:flutter/widgets.dart'; | ||||||
| import 'package:flutter_bloc/flutter_bloc.dart'; | import 'package:flutter_bloc/flutter_bloc.dart'; | ||||||
|  | import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; | ||||||
| 
 | 
 | ||||||
| class MockSettings { | class MockSettings { | ||||||
|   static MockSettings? _instance; |   static MockSettings? _instance; | ||||||
| @ -73,6 +74,7 @@ Future<void> bootstrap(FutureOr<Widget> Function() builder) async { | |||||||
|         await Firebase.initializeApp( |         await Firebase.initializeApp( | ||||||
|           options: DefaultFirebaseOptions.currentPlatform, |           options: DefaultFirebaseOptions.currentPlatform, | ||||||
|         ); |         ); | ||||||
|  |         await FirebaseAuth.instance.useAuthEmulator('localhost', 9099); | ||||||
|       } |       } | ||||||
|       await GetItInitializer.init(); |       await GetItInitializer.init(); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -50,6 +50,7 @@ abstract class GetItInitializer { | |||||||
|                   ), |                   ), | ||||||
|                 ]) |                 ]) | ||||||
|             : () => AuthenticationFirebaseDataSourceImpl( |             : () => AuthenticationFirebaseDataSourceImpl( | ||||||
|  |                 firebaseAuth: FirebaseAuth.instance, | ||||||
|                 googleSignIn: GoogleSignIn( |                 googleSignIn: GoogleSignIn( | ||||||
|                     clientId: DefaultFirebaseOptions.ios.iosClientId)), |                     clientId: DefaultFirebaseOptions.ios.iosClientId)), | ||||||
|       ) |       ) | ||||||
|  | |||||||
| @ -24,10 +24,7 @@ class DefaultFirebaseOptions { | |||||||
|     } |     } | ||||||
|     switch (defaultTargetPlatform) { |     switch (defaultTargetPlatform) { | ||||||
|       case TargetPlatform.android: |       case TargetPlatform.android: | ||||||
|         throw UnsupportedError( |         return android; | ||||||
|           'DefaultFirebaseOptions have not been configured for android - ' |  | ||||||
|           'you can reconfigure this by running the FlutterFire CLI again.', |  | ||||||
|         ); |  | ||||||
|       case TargetPlatform.iOS: |       case TargetPlatform.iOS: | ||||||
|         return ios; |         return ios; | ||||||
|       case TargetPlatform.macOS: |       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( |   static const FirebaseOptions ios = FirebaseOptions( | ||||||
|     apiKey: 'AIzaSyDDmtf0KN7Xw12_pqUsxoBfAxMuvCMmMmk', |     apiKey: 'AIzaSyCDbbhjbFrQwLXuIANdJzjkDk8uOETnn7w', | ||||||
|     appId: '1:405351917235:ios:869f0ad8ace08db899f2c6', |     appId: '1:136771801992:ios:bcdca68d2b7d227097203d', | ||||||
|     messagingSenderId: '405351917235', |     messagingSenderId: '136771801992', | ||||||
|     projectId: 'meerabel-dev', |     projectId: 'tchat-beta', | ||||||
|     storageBucket: 'meerabel-dev.appspot.com', |     databaseURL: 'https://tchat-beta.firebaseio.com', | ||||||
|     androidClientId: |     storageBucket: 'tchat-beta.appspot.com', | ||||||
|         '405351917235-4g1dh3475tq6t1sa2qoh7ol60nf4ta05.apps.googleusercontent.com', |     androidClientId: '136771801992-n2pq8oqutvrqj58e05hbavvc7n1jdfjb.apps.googleusercontent.com', | ||||||
|     iosClientId: |     iosClientId: '136771801992-p629tpo9bk3hcm2955s5ahivdla57ln9.apps.googleusercontent.com', | ||||||
|         '405351917235-2jv4ff02kovoim58f8d6d0rsa14apgkj.apps.googleusercontent.com', |  | ||||||
|     iosBundleId: 'com.example.exampleRouter', |     iosBundleId: 'com.example.exampleRouter', | ||||||
|   ); |   ); | ||||||
| } | } | ||||||
|  | |||||||
| @ -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/routes/router.dart'; | ||||||
| import 'package:example_router/core/utils/custom_password.dart'; | import 'package:example_router/core/utils/custom_password.dart'; | ||||||
| import 'package:example_router/core/utils/forms.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/material.dart'; | ||||||
| import 'package:flutter_bloc/flutter_bloc.dart'; | import 'package:flutter_bloc/flutter_bloc.dart'; | ||||||
| import 'package:go_router/go_router.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_type_utils/wyatt_type_utils.dart'; | ||||||
| import 'package:wyatt_architecture/wyatt_architecture.dart'; | import 'package:wyatt_architecture/wyatt_architecture.dart'; | ||||||
| 
 | 
 | ||||||
| FutureOrResult<int?> onSignUpSuccess( |  | ||||||
|   AuthenticationRepository<int> repo, |  | ||||||
|   Account? account, |  | ||||||
|   WyattForm form, |  | ||||||
| ) async { |  | ||||||
|   const id = -1; |  | ||||||
|   final confirmedPassword = |  | ||||||
|       form.valueOf<String?>(AppFormField.confirmedPassword); |  | ||||||
| 
 |  | ||||||
|   debugPrint( |  | ||||||
|       'onSignUpSuccess: $account, generatedId: $id, extraFormData: $confirmedPassword'); |  | ||||||
|   return const Ok<int, AppException>(id); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| FutureOrResult<int?> onAccountChanges( | FutureOrResult<int?> onAccountChanges( | ||||||
|   AuthenticationRepository<int> repo, |   AuthenticationRepository<int> repo, | ||||||
|   Account? account, |   AuthChangeEvent? authEvent, | ||||||
| ) async { | ) async { | ||||||
|  |   if (authEvent is SignInAuthChangeEvent || authEvent is RefreshAuthChangeEvent) { | ||||||
|     final id = Random().nextInt(1000); |     final id = Random().nextInt(1000); | ||||||
|     final token = |     final token = | ||||||
|         await repo.getIdentityToken().fold((value) => value, (error) => 'null'); |         await repo.getIdentityToken().fold((value) => value, (error) => 'null'); | ||||||
| 
 | 
 | ||||||
|   debugPrint('onAccountChanges: $account, token: $token, generatedId: $id'); |     debugPrint('onAccountChanges: ${authEvent?.account}, type: ${authEvent.runtimeType}, token: $token, generatedId: $id'); | ||||||
|     return Ok<int, AppException>(id); |     return Ok<int, AppException>(id); | ||||||
|  |   } else { | ||||||
|  |     return Err(ClientException('Not supported auth change logic')); | ||||||
|  |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| class App extends StatelessWidget { | class App extends StatelessWidget { | ||||||
| @ -61,7 +52,6 @@ class App extends StatelessWidget { | |||||||
|       AuthenticationRepositoryImpl( |       AuthenticationRepositoryImpl( | ||||||
|     authenticationCacheDataSource: getIt<AuthenticationCacheDataSource<int>>(), |     authenticationCacheDataSource: getIt<AuthenticationCacheDataSource<int>>(), | ||||||
|     authenticationRemoteDataSource: getIt<AuthenticationRemoteDataSource>(), |     authenticationRemoteDataSource: getIt<AuthenticationRemoteDataSource>(), | ||||||
|     onSignUpSuccess: onSignUpSuccess, |  | ||||||
|     onAuthChange: onAccountChanges, |     onAuthChange: onAccountChanges, | ||||||
|     customPasswordValidator: const CustomPassword.pure(), |     customPasswordValidator: const CustomPassword.pure(), | ||||||
|     extraSignUpInputs: [ |     extraSignUpInputs: [ | ||||||
| @ -127,7 +117,7 @@ class App extends StatelessWidget { | |||||||
|             value: authenticationCubit, |             value: authenticationCubit, | ||||||
|           ), |           ), | ||||||
|           BlocProvider<SignUpCubit<int>>( |           BlocProvider<SignUpCubit<int>>( | ||||||
|             create: (_) => SignUpCubit( |             create: (_) => CustomSignUpCubit( | ||||||
|               authenticationRepository: authenticationRepository, |               authenticationRepository: authenticationRepository, | ||||||
|             ), |             ), | ||||||
|           ), |           ), | ||||||
|  | |||||||
| @ -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 <https://www.gnu.org/licenses/>. | ||||||
|  | 
 | ||||||
|  | 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<int>{ | ||||||
|  |   CustomSignUpCubit({ | ||||||
|  |     required super.authenticationRepository, | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   FutureOrResult<void> onSignUpWithEmailAndPassword( | ||||||
|  |       Result<Account, AppException> result, WyattForm form) async { | ||||||
|  |     if (result.isOk) { | ||||||
|  |       await Future.delayed(const Duration(seconds: 3)); | ||||||
|  |       const id = -1; | ||||||
|  |       final confirmedPassword = | ||||||
|  |           form.valueOf<String?>(AppFormField.confirmedPassword); | ||||||
|  | 
 | ||||||
|  |       debugPrint( | ||||||
|  |           'onSignUpSuccess: ${result.ok}, generatedId: $id, intFormData: $confirmedPassword'); | ||||||
|  |       return const Ok<int, AppException>(id); | ||||||
|  |     } | ||||||
|  |     return const Ok(null); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -106,7 +106,7 @@ class _SignUpButton extends StatelessWidget { | |||||||
|         return status.isSubmissionInProgress |         return status.isSubmissionInProgress | ||||||
|             ? const CircularProgressIndicator() |             ? const CircularProgressIndicator() | ||||||
|             : ElevatedButton( |             : ElevatedButton( | ||||||
|                 onPressed: status.isValidated ? () => cubit.submit() : null, |                 onPressed: status.isValidated ? () => cubit.signUpWithEmailPassword() : null, | ||||||
|                 child: const Text('Sign up'), |                 child: const Text('Sign up'), | ||||||
|               ); |               ); | ||||||
|       }), |       }), | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user