auth_service.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import 'package:dartz/dartz.dart';
  2. import 'package:easy_localization/easy_localization.dart';
  3. import 'package:flowy_infra/uuid.dart';
  4. import 'package:appflowy_backend/dispatch/dispatch.dart';
  5. import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
  6. import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
  7. show SignInPayloadPB, SignUpPayloadPB, UserProfilePB;
  8. import '../../generated/locale_keys.g.dart';
  9. class AuthService {
  10. Future<Either<UserProfilePB, FlowyError>> signIn(
  11. {required String? email, required String? password}) {
  12. //
  13. final request = SignInPayloadPB.create()
  14. ..email = email ?? ''
  15. ..password = password ?? '';
  16. return UserEventSignIn(request).send();
  17. }
  18. Future<Either<UserProfilePB, FlowyError>> signUp(
  19. {required String? name,
  20. required String? password,
  21. required String? email}) {
  22. final request = SignUpPayloadPB.create()
  23. ..email = email ?? ''
  24. ..name = name ?? ''
  25. ..password = password ?? '';
  26. return UserEventSignUp(request).send();
  27. // return UserEventSignUp(request).send().then((result) {
  28. // return result.fold((userProfile) async {
  29. // return await FolderEventCreateDefaultWorkspace().send().then((result) {
  30. // return result.fold((workspaceIdentifier) {
  31. // return left(Tuple2(userProfile, workspaceIdentifier.workspaceId));
  32. // }, (error) {
  33. // throw UnimplementedError;
  34. // });
  35. // });
  36. // }, (error) => right(error));
  37. // });
  38. }
  39. Future<Either<Unit, FlowyError>> signOut() {
  40. return UserEventSignOut().send();
  41. }
  42. Future<Either<UserProfilePB, FlowyError>> autoSignUp() {
  43. const password = "AppFlowy123@";
  44. final uid = uuid();
  45. final userEmail = "[email protected]";
  46. return signUp(
  47. name: LocaleKeys.defaultUsername.tr(),
  48. password: password,
  49. email: userEmail,
  50. );
  51. }
  52. }