docs(authentication): update example
This commit is contained in:
@@ -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,
|
||||
),
|
||||
),
|
||||
|
||||
+46
@@ -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);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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'),
|
||||
);
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user