docs(authentication): update example
This commit is contained in:
parent
33cb4f6f06
commit
828c1ace6f
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",
|
||||
"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"
|
||||
}
|
@ -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<void> bootstrap(FutureOr<Widget> Function() builder) async {
|
||||
await Firebase.initializeApp(
|
||||
options: DefaultFirebaseOptions.currentPlatform,
|
||||
);
|
||||
await FirebaseAuth.instance.useAuthEmulator('localhost', 9099);
|
||||
}
|
||||
await GetItInitializer.init();
|
||||
|
||||
|
@ -50,6 +50,7 @@ abstract class GetItInitializer {
|
||||
),
|
||||
])
|
||||
: () => AuthenticationFirebaseDataSourceImpl(
|
||||
firebaseAuth: FirebaseAuth.instance,
|
||||
googleSignIn: GoogleSignIn(
|
||||
clientId: DefaultFirebaseOptions.ios.iosClientId)),
|
||||
)
|
||||
|
@ -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',
|
||||
);
|
||||
}
|
||||
|
@ -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<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(
|
||||
AuthenticationRepository<int> 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<int, AppException>(id);
|
||||
debugPrint('onAccountChanges: ${authEvent?.account}, type: ${authEvent.runtimeType}, token: $token, generatedId: $id');
|
||||
return Ok<int, AppException>(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<AuthenticationCacheDataSource<int>>(),
|
||||
authenticationRemoteDataSource: getIt<AuthenticationRemoteDataSource>(),
|
||||
onSignUpSuccess: onSignUpSuccess,
|
||||
onAuthChange: onAccountChanges,
|
||||
customPasswordValidator: const CustomPassword.pure(),
|
||||
extraSignUpInputs: [
|
||||
@ -127,7 +117,7 @@ class App extends StatelessWidget {
|
||||
value: authenticationCubit,
|
||||
),
|
||||
BlocProvider<SignUpCubit<int>>(
|
||||
create: (_) => SignUpCubit(
|
||||
create: (_) => CustomSignUpCubit(
|
||||
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
|
||||
? const CircularProgressIndicator()
|
||||
: ElevatedButton(
|
||||
onPressed: status.isValidated ? () => cubit.submit() : null,
|
||||
onPressed: status.isValidated ? () => cubit.signUpWithEmailPassword() : null,
|
||||
child: const Text('Sign up'),
|
||||
);
|
||||
}),
|
||||
|
Loading…
x
Reference in New Issue
Block a user