auth_service.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
  2. import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pbserver.dart';
  3. import 'package:dartz/dartz.dart';
  4. class AuthServiceMapKeys {
  5. const AuthServiceMapKeys._();
  6. // for supabase auth use only.
  7. static const String uuid = 'uuid';
  8. static const String email = 'email';
  9. static const String deviceId = 'device_id';
  10. static const String signInURL = 'sign_in_url';
  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. /// - `params`: Additional parameters for authentication (optional).
  22. ///
  23. /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
  24. Future<Either<FlowyError, UserProfilePB>> signIn({
  25. required String email,
  26. required String password,
  27. Map<String, String> params,
  28. });
  29. /// Registers a new user with their name, email, and password.
  30. ///
  31. /// - `name`: The name of the user.
  32. /// - `email`: The email address of the user.
  33. /// - `password`: The password of the user.
  34. /// - `params`: Additional parameters for registration (optional).
  35. ///
  36. /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
  37. Future<Either<FlowyError, UserProfilePB>> signUp({
  38. required String name,
  39. required String email,
  40. required String password,
  41. Map<String, String> params,
  42. });
  43. /// Registers a new user with an OAuth platform.
  44. ///
  45. /// - `platform`: The OAuth platform name.
  46. /// - `params`: Additional parameters for OAuth registration (optional).
  47. ///
  48. /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
  49. Future<Either<FlowyError, UserProfilePB>> signUpWithOAuth({
  50. required String platform,
  51. Map<String, String> params,
  52. });
  53. /// Registers a user as a guest.
  54. ///
  55. /// - `params`: Additional parameters for guest registration (optional).
  56. ///
  57. /// Returns a default [UserProfilePB].
  58. Future<Either<FlowyError, UserProfilePB>> signUpAsGuest({
  59. Map<String, String> params,
  60. });
  61. /// Authenticates a user with a magic link sent to their email.
  62. ///
  63. /// - `email`: The email address of the user.
  64. /// - `params`: Additional parameters for authentication with magic link (optional).
  65. ///
  66. /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
  67. Future<Either<FlowyError, UserProfilePB>> signInWithMagicLink({
  68. required String email,
  69. Map<String, String> params,
  70. });
  71. /// Signs out the currently authenticated user.
  72. Future<void> signOut();
  73. /// Retrieves the currently authenticated user's profile.
  74. ///
  75. /// Returns [UserProfilePB] if the user has signed in, otherwise returns [FlowyError].
  76. Future<Either<FlowyError, UserProfilePB>> getUser();
  77. }