|
| 1 | +import 'package:easy_localization/easy_localization.dart'; |
| 2 | + |
| 3 | +import '../../../../../core/local_storage/local_storage.dart'; |
| 4 | +import '../../../../../shared/types/response_type.dart'; |
| 5 | +import '../../../../../shared/utils/task_utils.dart'; |
| 6 | +import '../../../constants/auth_constants.dart'; |
| 7 | +import '../../../domain/entities/credentials.dart'; |
| 8 | +import '../../models/credentials_model.dart'; |
| 9 | +import 'auth_remote_data_source.dart'; |
| 10 | + |
| 11 | +/// A fake implementation of [AuthRemoteDataSource] for demonstration purposes. |
| 12 | +/// This class is used when Firebase is not enabled in the application. |
| 13 | +class AuthRemoteDataSourceDemoImpl implements AuthRemoteDataSource { |
| 14 | + AuthRemoteDataSourceDemoImpl(this._localStorage); |
| 15 | + |
| 16 | + final CoreLocalStorage _localStorage; |
| 17 | + |
| 18 | + final userId = 'demo_user_id'; |
| 19 | + String userName = 'Demo User'; |
| 20 | + String userEmail = 'demo@example.com'; |
| 21 | + |
| 22 | + @override |
| 23 | + TaskResponse<CredentialsModel> signIn({ |
| 24 | + required String email, |
| 25 | + required String password, |
| 26 | + }) { |
| 27 | + userEmail = email; |
| 28 | + |
| 29 | + return TaskResponse.right( |
| 30 | + CredentialsModel( |
| 31 | + userId: userId, |
| 32 | + name: userName, |
| 33 | + email: userEmail, |
| 34 | + provider: AuthProvider.email.name, |
| 35 | + ), |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + @override |
| 40 | + TaskResponse<void> signOut() => |
| 41 | + task(() async {}, (_) => tr('auth.errors.sign_out_failed')); |
| 42 | + |
| 43 | + @override |
| 44 | + TaskResponse<CredentialsModel> signUp({ |
| 45 | + required String name, |
| 46 | + required String email, |
| 47 | + required String password, |
| 48 | + }) { |
| 49 | + userName = name; |
| 50 | + userEmail = email; |
| 51 | + |
| 52 | + return TaskResponse.right( |
| 53 | + CredentialsModel( |
| 54 | + userId: userId, |
| 55 | + name: userName, |
| 56 | + email: userEmail, |
| 57 | + provider: AuthProvider.email.name, |
| 58 | + ), |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + @override |
| 63 | + TaskResponse<CredentialsModel> signWithApple() => TaskResponse.right( |
| 64 | + CredentialsModel( |
| 65 | + userId: userId, |
| 66 | + name: userName, |
| 67 | + email: 'apple@example.com', |
| 68 | + provider: AuthProvider.apple.name, |
| 69 | + ), |
| 70 | + ); |
| 71 | + |
| 72 | + @override |
| 73 | + TaskResponse<CredentialsModel> signWithGoogle() => TaskResponse.right( |
| 74 | + CredentialsModel( |
| 75 | + userId: userId, |
| 76 | + name: userName, |
| 77 | + email: 'google@example.com', |
| 78 | + provider: AuthProvider.google.name, |
| 79 | + ), |
| 80 | + ); |
| 81 | + |
| 82 | + @override |
| 83 | + TaskResponse<CredentialsModel> updateUser({ |
| 84 | + required AuthProvider provider, |
| 85 | + String? name, |
| 86 | + String? currentPassword, |
| 87 | + String? newPassword, |
| 88 | + }) => task( |
| 89 | + () async { |
| 90 | + if (name != null) { |
| 91 | + userName = name; |
| 92 | + } |
| 93 | + |
| 94 | + final data = await _localStorage.secureStorage.get<CredentialsModel>( |
| 95 | + AuthConstants.userKey, |
| 96 | + CredentialsModel.fromJson, |
| 97 | + ); |
| 98 | + |
| 99 | + if (data != null && data.email.isNotEmpty) { |
| 100 | + userEmail = data.email; |
| 101 | + } |
| 102 | + |
| 103 | + return CredentialsModel( |
| 104 | + userId: userId, |
| 105 | + name: userName, |
| 106 | + email: userEmail, |
| 107 | + provider: provider.name, |
| 108 | + ); |
| 109 | + }, |
| 110 | + (_) => tr('auth.errors.update_failed'), |
| 111 | + ); |
| 112 | +} |
0 commit comments