| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  | import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart'; | 
					
						
							|  |  |  | import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pbserver.dart'; | 
					
						
							|  |  |  | import 'package:dartz/dartz.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AuthServiceMapKeys { | 
					
						
							|  |  |  |   const AuthServiceMapKeys._(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // for supabase auth use only.
 | 
					
						
							|  |  |  |   static const String uuid = 'uuid'; | 
					
						
							| 
									
										
										
										
											2023-07-14 13:37:13 +08:00
										 |  |  |   static const String email = 'email'; | 
					
						
							| 
									
										
										
										
											2023-08-12 17:36:31 +08:00
										 |  |  |   static const String deviceId = 'device_id'; | 
					
						
							| 
									
										
										
										
											2023-10-07 09:58:44 +08:00
										 |  |  |   static const String signInURL = 'sign_in_url'; | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-24 14:00:34 +08:00
										 |  |  | /// `AuthService` is an abstract class that defines methods related to user authentication.
 | 
					
						
							|  |  |  | ///
 | 
					
						
							|  |  |  | /// This service provides various methods for user sign-in, sign-up,
 | 
					
						
							|  |  |  | /// OAuth-based registration, and other related functionalities.
 | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  | abstract class AuthService { | 
					
						
							| 
									
										
										
										
											2023-08-24 14:00:34 +08:00
										 |  |  |   /// Authenticates a user with their email and password.
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							|  |  |  |   /// - `email`: The email address of the user.
 | 
					
						
							|  |  |  |   /// - `password`: The password of the user.
 | 
					
						
							|  |  |  |   /// - `params`: Additional parameters for authentication (optional).
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |   /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
 | 
					
						
							| 
									
										
										
										
											2023-08-24 14:00:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |   Future<Either<FlowyError, UserProfilePB>> signIn({ | 
					
						
							|  |  |  |     required String email, | 
					
						
							|  |  |  |     required String password, | 
					
						
							| 
									
										
										
										
											2023-08-22 15:40:22 +08:00
										 |  |  |     Map<String, String> params, | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-24 14:00:34 +08:00
										 |  |  |   /// Registers a new user with their name, email, and password.
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							|  |  |  |   /// - `name`: The name of the user.
 | 
					
						
							|  |  |  |   /// - `email`: The email address of the user.
 | 
					
						
							|  |  |  |   /// - `password`: The password of the user.
 | 
					
						
							|  |  |  |   /// - `params`: Additional parameters for registration (optional).
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |   /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
 | 
					
						
							|  |  |  |   Future<Either<FlowyError, UserProfilePB>> signUp({ | 
					
						
							|  |  |  |     required String name, | 
					
						
							|  |  |  |     required String email, | 
					
						
							|  |  |  |     required String password, | 
					
						
							| 
									
										
										
										
											2023-08-22 15:40:22 +08:00
										 |  |  |     Map<String, String> params, | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-24 14:00:34 +08:00
										 |  |  |   /// Registers a new user with an OAuth platform.
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							|  |  |  |   /// - `platform`: The OAuth platform name.
 | 
					
						
							|  |  |  |   /// - `params`: Additional parameters for OAuth registration (optional).
 | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |   ///
 | 
					
						
							| 
									
										
										
										
											2023-08-24 14:00:34 +08:00
										 |  |  |   /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
 | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |   Future<Either<FlowyError, UserProfilePB>> signUpWithOAuth({ | 
					
						
							|  |  |  |     required String platform, | 
					
						
							| 
									
										
										
										
											2023-08-22 15:40:22 +08:00
										 |  |  |     Map<String, String> params, | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-24 14:00:34 +08:00
										 |  |  |   /// Registers a user as a guest.
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							|  |  |  |   /// - `params`: Additional parameters for guest registration (optional).
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							|  |  |  |   /// Returns a default [UserProfilePB].
 | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |   Future<Either<FlowyError, UserProfilePB>> signUpAsGuest({ | 
					
						
							| 
									
										
										
										
											2023-08-22 15:40:22 +08:00
										 |  |  |     Map<String, String> params, | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-24 14:00:34 +08:00
										 |  |  |   /// Authenticates a user with a magic link sent to their email.
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							|  |  |  |   /// - `email`: The email address of the user.
 | 
					
						
							|  |  |  |   /// - `params`: Additional parameters for authentication with magic link (optional).
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							|  |  |  |   /// Returns [UserProfilePB] if the user is authenticated, otherwise returns [FlowyError].
 | 
					
						
							| 
									
										
										
										
											2023-08-03 08:48:04 +08:00
										 |  |  |   Future<Either<FlowyError, UserProfilePB>> signInWithMagicLink({ | 
					
						
							|  |  |  |     required String email, | 
					
						
							| 
									
										
										
										
											2023-08-22 15:40:22 +08:00
										 |  |  |     Map<String, String> params, | 
					
						
							| 
									
										
										
										
											2023-08-03 08:48:04 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-24 14:00:34 +08:00
										 |  |  |   /// Signs out the currently authenticated user.
 | 
					
						
							| 
									
										
										
										
											2023-07-14 13:37:13 +08:00
										 |  |  |   Future<void> signOut(); | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-24 14:00:34 +08:00
										 |  |  |   /// Retrieves the currently authenticated user's profile.
 | 
					
						
							|  |  |  |   ///
 | 
					
						
							|  |  |  |   /// Returns [UserProfilePB] if the user has signed in, otherwise returns [FlowyError].
 | 
					
						
							| 
									
										
										
										
											2023-05-21 18:53:59 +08:00
										 |  |  |   Future<Either<FlowyError, UserProfilePB>> getUser(); | 
					
						
							|  |  |  | } |