auth_service.dart 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }
  11. /// `AuthService` is an abstract class that defines methods related to user authentication.
  12. ///
  13. /// This service provides various methods for user sign-in, sign-up,
  14. /// OAuth-based registration, and other related functionalities.
  15. abstract class AuthService {
  16. /// Authenticates a user with their email and password.
  17. ///
  18. /// - `email`: The email address of the user.
  19. /// - `password`: The password of the user.
  20. /// - `params`: Additional parameters for authentication (optional).
  21. ///
  22. /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
  23. Future<Either<FlowyError, UserProfilePB>> signIn({
  24. required String email,
  25. required String password,
  26. Map<String, String> params,
  27. });
  28. /// Registers a new user with their name, email, and password.
  29. ///
  30. /// - `name`: The name of the user.
  31. /// - `email`: The email address of the user.
  32. /// - `password`: The password of the user.
  33. /// - `params`: Additional parameters for registration (optional).
  34. ///
  35. /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
  36. Future<Either<FlowyError, UserProfilePB>> signUp({
  37. required String name,
  38. required String email,
  39. required String password,
  40. Map<String, String> params,
  41. });
  42. /// Registers a new user with an OAuth platform.
  43. ///
  44. /// - `platform`: The OAuth platform name.
  45. /// - `params`: Additional parameters for OAuth registration (optional).
  46. ///
  47. /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
  48. Future<Either<FlowyError, UserProfilePB>> signUpWithOAuth({
  49. required String platform,
  50. Map<String, String> params,
  51. });
  52. /// Registers a user as a guest.
  53. ///
  54. /// - `params`: Additional parameters for guest registration (optional).
  55. ///
  56. /// Returns a default [UserProfilePB].
  57. Future<Either<FlowyError, UserProfilePB>> signUpAsGuest({
  58. Map<String, String> params,
  59. });
  60. /// Authenticates a user with a magic link sent to their email.
  61. ///
  62. /// - `email`: The email address of the user.
  63. /// - `params`: Additional parameters for authentication with magic link (optional).
  64. ///
  65. /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
  66. Future<Either<FlowyError, UserProfilePB>> signInWithMagicLink({
  67. required String email,
  68. Map<String, String> params,
  69. });
  70. /// Signs out the currently authenticated user.
  71. Future<void> signOut();
  72. /// Retrieves the currently authenticated user's profile.
  73. ///
  74. /// Returns [UserProfilePB] if the user has signed in, otherwise returns [FlowyError].
  75. Future<Either<FlowyError, UserProfilePB>> getUser();
  76. }