mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: put Auth business logic in a service
This commit is contained in:
parent
e7033aa6e8
commit
33c758e711
@ -3,7 +3,7 @@ import 'package:flowy_sdk/dispatch/dispatch.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show SignInPayload, SignUpPayload, UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
|
||||
class AuthRepository {
|
||||
class AuthService {
|
||||
Future<Either<UserProfile, FlowyError>> signIn({required String? email, required String? password}) {
|
||||
//
|
||||
final request = SignInPayload.create()
|
@ -1,4 +1,4 @@
|
||||
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
|
||||
import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile, ErrorCode;
|
||||
@ -8,8 +8,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
part 'sign_in_bloc.freezed.dart';
|
||||
|
||||
class SignInBloc extends Bloc<SignInEvent, SignInState> {
|
||||
final AuthRepository authRepo;
|
||||
SignInBloc(this.authRepo) : super(SignInState.initial()) {
|
||||
final AuthService authService;
|
||||
SignInBloc(this.authService) : super(SignInState.initial()) {
|
||||
on<SignInEvent>((event, emit) async {
|
||||
await event.map(
|
||||
signedInWithUserEmailAndPassword: (e) async {
|
||||
@ -31,7 +31,7 @@ class SignInBloc extends Bloc<SignInEvent, SignInState> {
|
||||
Future<void> _performActionOnSignIn(SignInState state, Emitter<SignInState> emit) async {
|
||||
emit(state.copyWith(isSubmitting: true, emailError: none(), passwordError: none(), successOrFail: none()));
|
||||
|
||||
final result = await authRepo.signIn(
|
||||
final result = await authService.signIn(
|
||||
email: state.email,
|
||||
password: state.password,
|
||||
);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
|
||||
import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile, ErrorCode;
|
||||
@ -10,8 +10,8 @@ import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||
part 'sign_up_bloc.freezed.dart';
|
||||
|
||||
class SignUpBloc extends Bloc<SignUpEvent, SignUpState> {
|
||||
final AuthRepository autoRepo;
|
||||
SignUpBloc(this.autoRepo) : super(SignUpState.initial()) {
|
||||
final AuthService authService;
|
||||
SignUpBloc(this.authService) : super(SignUpState.initial()) {
|
||||
on<SignUpEvent>((event, emit) async {
|
||||
await event.map(signUpWithUserEmailAndPassword: (e) async {
|
||||
await _performActionOnSignUp(emit);
|
||||
@ -62,7 +62,7 @@ class SignUpBloc extends Bloc<SignUpEvent, SignUpState> {
|
||||
repeatPasswordError: none(),
|
||||
));
|
||||
|
||||
final result = await autoRepo.signUp(
|
||||
final result = await authService.signUp(
|
||||
name: state.email,
|
||||
password: state.password,
|
||||
email: state.email,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:app_flowy/user/application/sign_in_bloc.dart';
|
||||
import 'package:app_flowy/user/application/sign_up_bloc.dart';
|
||||
import 'package:app_flowy/user/application/splash_bloc.dart';
|
||||
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
|
||||
import 'package:app_flowy/user/infrastructure/router.dart';
|
||||
import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart';
|
||||
import 'package:app_flowy/workspace/application/home/home_bloc.dart';
|
||||
@ -11,14 +11,14 @@ import 'network_monitor.dart';
|
||||
|
||||
class UserDepsResolver {
|
||||
static Future<void> resolve(GetIt getIt) async {
|
||||
getIt.registerFactory<AuthRepository>(() => AuthRepository());
|
||||
getIt.registerFactory<AuthService>(() => AuthService());
|
||||
|
||||
//Interface implementation
|
||||
getIt.registerFactory<AuthRouter>(() => AuthRouter());
|
||||
|
||||
//Bloc
|
||||
getIt.registerFactory<SignInBloc>(() => SignInBloc(getIt<AuthRepository>()));
|
||||
getIt.registerFactory<SignUpBloc>(() => SignUpBloc(getIt<AuthRepository>()));
|
||||
getIt.registerFactory<SignInBloc>(() => SignInBloc(getIt<AuthService>()));
|
||||
getIt.registerFactory<SignUpBloc>(() => SignUpBloc(getIt<AuthService>()));
|
||||
|
||||
getIt.registerFactory<SplashRoute>(() => SplashRoute());
|
||||
getIt.registerFactory<HomeBloc>(() => HomeBloc());
|
||||
|
@ -1,5 +1,5 @@
|
||||
import 'package:app_flowy/startup/startup.dart';
|
||||
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
|
||||
import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:app_flowy/user/presentation/sign_in_screen.dart';
|
||||
import 'package:app_flowy/user/presentation/sign_up_screen.dart';
|
||||
import 'package:app_flowy/user/presentation/skip_log_in_screen.dart';
|
||||
@ -69,7 +69,7 @@ class SplashRoute {
|
||||
PageRoutes.fade(
|
||||
() => SkipLogInScreen(
|
||||
router: getIt<AuthRouter>(),
|
||||
authRepo: getIt<AuthRepository>(),
|
||||
authService: getIt<AuthService>(),
|
||||
),
|
||||
RouteDurations.slow.inMilliseconds * .001),
|
||||
);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:app_flowy/user/application/user_listener.dart';
|
||||
import 'package:app_flowy/user/infrastructure/router.dart';
|
||||
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
|
||||
import 'package:app_flowy/user/presentation/widgets/background.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra/size.dart';
|
||||
@ -21,12 +21,12 @@ import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||
|
||||
class SkipLogInScreen extends StatefulWidget {
|
||||
final AuthRouter router;
|
||||
final AuthRepository authRepo;
|
||||
final AuthService authService;
|
||||
|
||||
const SkipLogInScreen({
|
||||
Key? key,
|
||||
required this.router,
|
||||
required this.authRepo,
|
||||
required this.authService,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -99,7 +99,7 @@ class _SkipLogInScreenState extends State<SkipLogInScreen> {
|
||||
const password = "AppFlowy123@";
|
||||
final uid = uuid();
|
||||
final userEmail = "$uid@appflowy.io";
|
||||
final result = await widget.authRepo.signUp(
|
||||
final result = await widget.authService.signUp(
|
||||
name: LocaleKeys.defaultUsername.tr(),
|
||||
password: password,
|
||||
email: userEmail,
|
||||
|
Loading…
Reference in New Issue
Block a user