24 lines
709 B
Dart
24 lines
709 B
Dart
import '../../core/network/app_exceptions.dart';
|
|
import '../../core/utils/result.dart';
|
|
import '../models/user_model.dart';
|
|
import '../services/auth_service.dart';
|
|
|
|
class AuthRepository {
|
|
final AuthService _authService;
|
|
|
|
AuthRepository({required AuthService authService})
|
|
: _authService = authService;
|
|
|
|
Future<Result<UserModel>> login(String email, String password) async {
|
|
try {
|
|
final response = await _authService.login(email, password);
|
|
final user = UserModel(token: response['token'], name: response['name']);
|
|
return Result.ok(user);
|
|
} on Exception {
|
|
return Result.error(
|
|
AuthenticationException('Email or password is not correct.'),
|
|
);
|
|
}
|
|
}
|
|
}
|