| 
									
										
										
										
											2023-11-29 12:55:13 -08:00
										 |  |  | import 'package:appflowy/env/cloud_env.dart'; | 
					
						
							| 
									
										
										
										
											2024-04-22 14:04:55 +08:00
										 |  |  | import 'package:appflowy/generated/locale_keys.g.dart'; | 
					
						
							| 
									
										
										
										
											2023-11-29 12:55:13 -08:00
										 |  |  | import 'package:appflowy/startup/startup.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/startup/tasks/appflowy_cloud_task.dart'; | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  | import 'package:appflowy/user/application/auth/auth_service.dart'; | 
					
						
							| 
									
										
										
										
											2024-08-27 10:49:31 +08:00
										 |  |  | import 'package:appflowy_backend/log.dart'; | 
					
						
							| 
									
										
										
										
											2023-01-08 12:10:53 +08:00
										 |  |  | import 'package:appflowy_backend/protobuf/flowy-error/code.pb.dart'; | 
					
						
							|  |  |  | import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart'; | 
					
						
							|  |  |  | import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart' | 
					
						
							|  |  |  |     show UserProfilePB; | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  | import 'package:appflowy_result/appflowy_result.dart'; | 
					
						
							| 
									
										
										
										
											2024-04-22 14:04:55 +08:00
										 |  |  | import 'package:easy_localization/easy_localization.dart'; | 
					
						
							| 
									
										
										
										
											2024-08-27 10:49:31 +08:00
										 |  |  | import 'package:flutter/foundation.dart'; | 
					
						
							| 
									
										
										
										
											2021-07-13 13:14:49 +08:00
										 |  |  | import 'package:flutter_bloc/flutter_bloc.dart'; | 
					
						
							| 
									
										
										
										
											2024-01-09 16:09:44 +07:00
										 |  |  | import 'package:freezed_annotation/freezed_annotation.dart'; | 
					
						
							| 
									
										
										
										
											2021-07-13 13:14:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | part 'sign_in_bloc.freezed.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SignInBloc extends Bloc<SignInEvent, SignInState> { | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |   SignInBloc(this.authService) : super(SignInState.initial()) { | 
					
						
							|  |  |  |     if (isAppFlowyCloudEnabled) { | 
					
						
							|  |  |  |       deepLinkStateListener = | 
					
						
							|  |  |  |           getIt<AppFlowyCloudDeepLink>().subscribeDeepLinkLoadingState((value) { | 
					
						
							|  |  |  |         if (isClosed) return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         add(SignInEvent.deepLinkStateChange(value)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     on<SignInEvent>( | 
					
						
							|  |  |  |       (event, emit) async { | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |         await event.when( | 
					
						
							|  |  |  |           signedInWithUserEmailAndPassword: () async => _onSignIn(emit), | 
					
						
							| 
									
										
										
										
											2024-06-11 22:17:29 +02:00
										 |  |  |           signedInWithOAuth: (platform) async => | 
					
						
							|  |  |  |               _onSignInWithOAuth(emit, platform), | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |           signedInAsGuest: () async => _onSignInAsGuest(emit), | 
					
						
							| 
									
										
										
										
											2024-06-11 22:17:29 +02:00
										 |  |  |           signedWithMagicLink: (email) async => | 
					
						
							|  |  |  |               _onSignInWithMagicLink(emit, email), | 
					
						
							|  |  |  |           deepLinkStateChange: (result) => _onDeepLinkStateChange(emit, result), | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |           cancel: () { | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |             emit( | 
					
						
							|  |  |  |               state.copyWith( | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |                 isSubmitting: false, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |                 emailError: null, | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |                 passwordError: null, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |                 successOrFail: null, | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |               ), | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |           emailChanged: (email) async { | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |             emit( | 
					
						
							|  |  |  |               state.copyWith( | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |                 email: email, | 
					
						
							|  |  |  |                 emailError: null, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |                 successOrFail: null, | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |               ), | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |           passwordChanged: (password) async { | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |             emit( | 
					
						
							|  |  |  |               state.copyWith( | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |                 password: password, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |                 passwordError: null, | 
					
						
							|  |  |  |                 successOrFail: null, | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |               ), | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2024-04-22 14:04:55 +08:00
										 |  |  |           switchLoginType: (type) { | 
					
						
							| 
									
										
										
										
											2024-06-11 22:17:29 +02:00
										 |  |  |             emit(state.copyWith(loginType: type)); | 
					
						
							| 
									
										
										
										
											2024-04-22 14:04:55 +08:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2024-01-25 16:37:36 +01:00
										 |  |  |         ); | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2021-07-13 13:14:49 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |   final AuthService authService; | 
					
						
							|  |  |  |   VoidCallback? deepLinkStateListener; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Future<void> close() { | 
					
						
							|  |  |  |     deepLinkStateListener?.call(); | 
					
						
							|  |  |  |     if (isAppFlowyCloudEnabled && deepLinkStateListener != null) { | 
					
						
							|  |  |  |       getIt<AppFlowyCloudDeepLink>().unsubscribeDeepLinkLoadingState( | 
					
						
							|  |  |  |         deepLinkStateListener!, | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return super.close(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Future<void> _onDeepLinkStateChange( | 
					
						
							|  |  |  |     Emitter<SignInState> emit, | 
					
						
							|  |  |  |     DeepLinkResult result, | 
					
						
							|  |  |  |   ) async { | 
					
						
							|  |  |  |     final deepLinkState = result.state; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (deepLinkState) { | 
					
						
							|  |  |  |       case DeepLinkState.none: | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case DeepLinkState.loading: | 
					
						
							|  |  |  |         emit( | 
					
						
							|  |  |  |           state.copyWith( | 
					
						
							|  |  |  |             isSubmitting: true, | 
					
						
							|  |  |  |             emailError: null, | 
					
						
							|  |  |  |             passwordError: null, | 
					
						
							|  |  |  |             successOrFail: null, | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |       case DeepLinkState.finish: | 
					
						
							|  |  |  |         final newState = result.result?.fold( | 
					
						
							|  |  |  |           (s) => state.copyWith( | 
					
						
							|  |  |  |             isSubmitting: false, | 
					
						
							|  |  |  |             successOrFail: FlowyResult.success(s), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |           (f) => _stateFromCode(f), | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         if (newState != null) { | 
					
						
							|  |  |  |           emit(newState); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-11 22:17:29 +02:00
										 |  |  |   Future<void> _onSignIn(Emitter<SignInState> emit) async { | 
					
						
							| 
									
										
										
										
											2023-11-27 18:54:31 -08:00
										 |  |  |     final result = await authService.signInWithEmailPassword( | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |       email: state.email ?? '', | 
					
						
							|  |  |  |       password: state.password ?? '', | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     emit( | 
					
						
							|  |  |  |       result.fold( | 
					
						
							|  |  |  |         (userProfile) => state.copyWith( | 
					
						
							|  |  |  |           isSubmitting: false, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |           successOrFail: FlowyResult.success(userProfile), | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |         ), | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |         (error) => _stateFromCode(error), | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |   Future<void> _onSignInWithOAuth( | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |     Emitter<SignInState> emit, | 
					
						
							|  |  |  |     String platform, | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |   ) async { | 
					
						
							|  |  |  |     emit( | 
					
						
							|  |  |  |       state.copyWith( | 
					
						
							| 
									
										
										
										
											2022-12-30 11:16:47 +08:00
										 |  |  |         isSubmitting: true, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |         emailError: null, | 
					
						
							|  |  |  |         passwordError: null, | 
					
						
							|  |  |  |         successOrFail: null, | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2021-07-13 13:14:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-11 22:17:29 +02:00
										 |  |  |     final result = await authService.signUpWithOAuth(platform: platform); | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |     emit( | 
					
						
							|  |  |  |       result.fold( | 
					
						
							|  |  |  |         (userProfile) => state.copyWith( | 
					
						
							|  |  |  |           isSubmitting: false, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |           successOrFail: FlowyResult.success(userProfile), | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |         ), | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |         (error) => _stateFromCode(error), | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |   Future<void> _onSignInWithMagicLink( | 
					
						
							| 
									
										
										
										
											2023-08-03 08:48:04 +08:00
										 |  |  |     Emitter<SignInState> emit, | 
					
						
							|  |  |  |     String email, | 
					
						
							|  |  |  |   ) async { | 
					
						
							|  |  |  |     emit( | 
					
						
							|  |  |  |       state.copyWith( | 
					
						
							|  |  |  |         isSubmitting: true, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |         emailError: null, | 
					
						
							|  |  |  |         passwordError: null, | 
					
						
							|  |  |  |         successOrFail: null, | 
					
						
							| 
									
										
										
										
											2023-08-03 08:48:04 +08:00
										 |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-11 22:17:29 +02:00
										 |  |  |     final result = await authService.signInWithMagicLink(email: email); | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-03 08:48:04 +08:00
										 |  |  |     emit( | 
					
						
							|  |  |  |       result.fold( | 
					
						
							| 
									
										
										
										
											2024-06-11 22:17:29 +02:00
										 |  |  |         (userProfile) => state.copyWith(isSubmitting: true), | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |         (error) => _stateFromCode(error), | 
					
						
							| 
									
										
										
										
											2023-08-03 08:48:04 +08:00
										 |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |   Future<void> _onSignInAsGuest( | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |     Emitter<SignInState> emit, | 
					
						
							|  |  |  |   ) async { | 
					
						
							|  |  |  |     emit( | 
					
						
							|  |  |  |       state.copyWith( | 
					
						
							|  |  |  |         isSubmitting: true, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |         emailError: null, | 
					
						
							|  |  |  |         passwordError: null, | 
					
						
							|  |  |  |         successOrFail: null, | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     final result = await authService.signUpAsGuest(); | 
					
						
							|  |  |  |     emit( | 
					
						
							|  |  |  |       result.fold( | 
					
						
							|  |  |  |         (userProfile) => state.copyWith( | 
					
						
							|  |  |  |           isSubmitting: false, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |           successOrFail: FlowyResult.success(userProfile), | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |         ), | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |         (error) => _stateFromCode(error), | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2021-07-13 13:14:49 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-07-25 18:04:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |   SignInState _stateFromCode(FlowyError error) { | 
					
						
							| 
									
										
										
										
											2024-08-27 10:49:31 +08:00
										 |  |  |     Log.error('SignInState _stateFromCode: ${error.msg}'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-22 00:19:15 +08:00
										 |  |  |     switch (error.code) { | 
					
						
							| 
									
										
										
										
											2021-08-31 11:32:51 +08:00
										 |  |  |       case ErrorCode.EmailFormatInvalid: | 
					
						
							| 
									
										
										
										
											2022-12-30 11:16:47 +08:00
										 |  |  |         return state.copyWith( | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |           isSubmitting: false, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |           emailError: error.msg, | 
					
						
							|  |  |  |           passwordError: null, | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2021-08-31 11:32:51 +08:00
										 |  |  |       case ErrorCode.PasswordFormatInvalid: | 
					
						
							| 
									
										
										
										
											2022-12-30 11:16:47 +08:00
										 |  |  |         return state.copyWith( | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |           isSubmitting: false, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |           passwordError: error.msg, | 
					
						
							|  |  |  |           emailError: null, | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2024-04-22 14:04:55 +08:00
										 |  |  |       case ErrorCode.UserUnauthorized: | 
					
						
							|  |  |  |         return state.copyWith( | 
					
						
							|  |  |  |           isSubmitting: false, | 
					
						
							|  |  |  |           successOrFail: FlowyResult.failure( | 
					
						
							|  |  |  |             FlowyError(msg: LocaleKeys.signIn_limitRateError.tr()), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2021-07-25 18:04:16 +08:00
										 |  |  |       default: | 
					
						
							| 
									
										
										
										
											2022-12-30 11:16:47 +08:00
										 |  |  |         return state.copyWith( | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |           isSubmitting: false, | 
					
						
							| 
									
										
										
										
											2024-04-22 14:04:55 +08:00
										 |  |  |           successOrFail: FlowyResult.failure( | 
					
						
							|  |  |  |             FlowyError(msg: LocaleKeys.signIn_generalError.tr()), | 
					
						
							|  |  |  |           ), | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2021-07-25 18:04:16 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-07-13 13:14:49 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-07-24 15:05:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | @freezed | 
					
						
							| 
									
										
										
										
											2022-03-25 15:02:43 +08:00
										 |  |  | class SignInEvent with _$SignInEvent { | 
					
						
							| 
									
										
										
										
											2022-12-30 11:16:47 +08:00
										 |  |  |   const factory SignInEvent.signedInWithUserEmailAndPassword() = | 
					
						
							|  |  |  |       SignedInWithUserEmailAndPassword; | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |   const factory SignInEvent.signedInWithOAuth(String platform) = | 
					
						
							|  |  |  |       SignedInWithOAuth; | 
					
						
							|  |  |  |   const factory SignInEvent.signedInAsGuest() = SignedInAsGuest; | 
					
						
							| 
									
										
										
										
											2023-08-03 08:48:04 +08:00
										 |  |  |   const factory SignInEvent.signedWithMagicLink(String email) = | 
					
						
							|  |  |  |       SignedWithMagicLink; | 
					
						
							| 
									
										
										
										
											2021-07-24 15:05:47 +08:00
										 |  |  |   const factory SignInEvent.emailChanged(String email) = EmailChanged; | 
					
						
							|  |  |  |   const factory SignInEvent.passwordChanged(String password) = PasswordChanged; | 
					
						
							| 
									
										
										
										
											2023-11-29 12:55:13 -08:00
										 |  |  |   const factory SignInEvent.deepLinkStateChange(DeepLinkResult result) = | 
					
						
							| 
									
										
										
										
											2024-04-11 16:33:28 +08:00
										 |  |  |       DeepLinkStateChange; | 
					
						
							| 
									
										
										
										
											2024-01-09 16:09:44 +07:00
										 |  |  |   const factory SignInEvent.cancel() = _Cancel; | 
					
						
							| 
									
										
										
										
											2024-04-22 14:04:55 +08:00
										 |  |  |   const factory SignInEvent.switchLoginType(LoginType type) = _SwitchLoginType; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // we support sign in directly without sign up, but we want to allow the users to sign up if they want to
 | 
					
						
							|  |  |  | // this type is only for the UI to know which form to show
 | 
					
						
							|  |  |  | enum LoginType { | 
					
						
							|  |  |  |   signIn, | 
					
						
							|  |  |  |   signUp, | 
					
						
							| 
									
										
										
										
											2021-07-24 15:05:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @freezed | 
					
						
							| 
									
										
										
										
											2022-03-25 15:02:43 +08:00
										 |  |  | class SignInState with _$SignInState { | 
					
						
							| 
									
										
										
										
											2021-07-24 15:05:47 +08:00
										 |  |  |   const factory SignInState({ | 
					
						
							|  |  |  |     String? email, | 
					
						
							|  |  |  |     String? password, | 
					
						
							|  |  |  |     required bool isSubmitting, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |     required String? passwordError, | 
					
						
							|  |  |  |     required String? emailError, | 
					
						
							|  |  |  |     required FlowyResult<UserProfilePB, FlowyError>? successOrFail, | 
					
						
							| 
									
										
										
										
											2024-04-22 14:04:55 +08:00
										 |  |  |     @Default(LoginType.signIn) LoginType loginType, | 
					
						
							| 
									
										
										
										
											2021-07-24 15:05:47 +08:00
										 |  |  |   }) = _SignInState; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |   factory SignInState.initial() => const SignInState( | 
					
						
							| 
									
										
										
										
											2021-07-24 15:05:47 +08:00
										 |  |  |         isSubmitting: false, | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |         passwordError: null, | 
					
						
							|  |  |  |         emailError: null, | 
					
						
							|  |  |  |         successOrFail: null, | 
					
						
							| 
									
										
										
										
											2021-07-24 15:05:47 +08:00
										 |  |  |       ); | 
					
						
							|  |  |  | } |