auth_service.dart 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
  2. import 'package:appflowy_backend/protobuf/flowy-user/auth.pb.dart';
  3. import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pbserver.dart';
  4. import 'package:dartz/dartz.dart';
  5. class AuthServiceMapKeys {
  6. const AuthServiceMapKeys._();
  7. // for supabase auth use only.
  8. static const String uuid = 'uuid';
  9. static const String email = 'email';
  10. static const String deviceId = 'device_id';
  11. }
  12. /// `AuthService` is an abstract class that defines methods related to user authentication.
  13. ///
  14. /// This service provides various methods for user sign-in, sign-up,
  15. /// OAuth-based registration, and other related functionalities.
  16. abstract class AuthService {
  17. /// Authenticates a user with their email and password.
  18. ///
  19. /// - `email`: The email address of the user.
  20. /// - `password`: The password of the user.
  21. /// - `authType`: The type of authentication (optional).
  22. /// - `params`: Additional parameters for authentication (optional).
  23. ///
  24. /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
  25. Future<Either<FlowyError, UserProfilePB>> signIn({
  26. required String email,
  27. required String password,
  28. AuthTypePB authType,
  29. Map<String, String> params,
  30. });
  31. /// Registers a new user with their name, email, and password.
  32. ///
  33. /// - `name`: The name of the user.
  34. /// - `email`: The email address of the user.
  35. /// - `password`: The password of the user.
  36. /// - `authType`: The type of authentication (optional).
  37. /// - `params`: Additional parameters for registration (optional).
  38. ///
  39. /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
  40. Future<Either<FlowyError, UserProfilePB>> signUp({
  41. required String name,
  42. required String email,
  43. required String password,
  44. AuthTypePB authType,
  45. Map<String, String> params,
  46. });
  47. /// Registers a new user with an OAuth platform.
  48. ///
  49. /// - `platform`: The OAuth platform name.
  50. /// - `authType`: The type of authentication (optional).
  51. /// - `params`: Additional parameters for OAuth registration (optional).
  52. ///
  53. /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
  54. Future<Either<FlowyError, UserProfilePB>> signUpWithOAuth({
  55. required String platform,
  56. AuthTypePB authType,
  57. Map<String, String> params,
  58. });
  59. /// Registers a user as a guest.
  60. ///
  61. /// - `authType`: The type of authentication (optional).
  62. /// - `params`: Additional parameters for guest registration (optional).
  63. ///
  64. /// Returns a default [UserProfilePB].
  65. Future<Either<FlowyError, UserProfilePB>> signUpAsGuest({
  66. AuthTypePB authType,
  67. Map<String, String> params,
  68. });
  69. /// Authenticates a user with a magic link sent to their email.
  70. ///
  71. /// - `email`: The email address of the user.
  72. /// - `params`: Additional parameters for authentication with magic link (optional).
  73. ///
  74. /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
  75. Future<Either<FlowyError, UserProfilePB>> signInWithMagicLink({
  76. required String email,
  77. Map<String, String> params,
  78. });
  79. /// Signs out the currently authenticated user.
  80. Future<void> signOut();
  81. /// Retrieves the currently authenticated user's profile.
  82. ///
  83. /// Returns [UserProfilePB] if the user has signed in, otherwise returns [FlowyError].
  84. Future<Either<FlowyError, UserProfilePB>> getUser();
  85. }