auth_service.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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,
  12. required String? password,
  13. }) {
  14. //
  15. final request = SignInPayloadPB.create()
  16. ..email = email ?? ''
  17. ..password = password ?? '';
  18. return UserEventSignIn(request).send();
  19. }
  20. Future<Either<UserProfilePB, FlowyError>> signUp({
  21. required String? name,
  22. required String? password,
  23. required String? email,
  24. }) {
  25. final request = SignUpPayloadPB.create()
  26. ..email = email ?? ''
  27. ..name = name ?? ''
  28. ..password = password ?? '';
  29. return UserEventSignUp(request).send();
  30. // return UserEventSignUp(request).send().then((result) {
  31. // return result.fold((userProfile) async {
  32. // return await FolderEventCreateDefaultWorkspace().send().then((result) {
  33. // return result.fold((workspaceIdentifier) {
  34. // return left(Tuple2(userProfile, workspaceIdentifier.workspaceId));
  35. // }, (error) {
  36. // throw UnimplementedError;
  37. // });
  38. // });
  39. // }, (error) => right(error));
  40. // });
  41. }
  42. Future<Either<Unit, FlowyError>> signOut() {
  43. return UserEventSignOut().send();
  44. }
  45. Future<Either<UserProfilePB, FlowyError>> autoSignUp() {
  46. const password = "AppFlowy123@";
  47. final uid = uuid();
  48. final userEmail = "[email protected]";
  49. return signUp(
  50. name: LocaleKeys.defaultUsername.tr(),
  51. password: password,
  52. email: userEmail,
  53. );
  54. }
  55. }