This commit is contained in:
Phuoc Nguyen
2025-10-10 17:51:31 +07:00
parent 10ccd0300d
commit 77440ac957
7 changed files with 300 additions and 11 deletions

View File

@@ -28,27 +28,39 @@ class AuthRepositoryImpl implements AuthRepository {
required String password,
}) async {
try {
print('🔐 Repository: Starting login...');
final loginDto = LoginDto(email: email, password: password);
final authResponse = await remoteDataSource.login(loginDto);
print('🔐 Repository: Got response, token length=${authResponse.accessToken.length}');
// Save token to secure storage
await secureStorage.saveAccessToken(authResponse.accessToken);
print('🔐 Repository: Token saved to secure storage');
// Set token in Dio client for subsequent requests
dioClient.setAuthToken(authResponse.accessToken);
print('🔐 Repository: Token set in DioClient');
return Right(authResponse);
} on InvalidCredentialsException catch (e) {
print('❌ Repository: InvalidCredentialsException - ${e.message}');
return Left(InvalidCredentialsFailure(e.message));
} on UnauthorizedException catch (e) {
print('❌ Repository: UnauthorizedException - ${e.message}');
return Left(UnauthorizedFailure(e.message));
} on ValidationException catch (e) {
print('❌ Repository: ValidationException - ${e.message}');
return Left(ValidationFailure(e.message));
} on NetworkException catch (e) {
print('❌ Repository: NetworkException - ${e.message}');
return Left(NetworkFailure(e.message));
} on ServerException catch (e) {
print('❌ Repository: ServerException - ${e.message}');
return Left(ServerFailure(e.message));
} catch (e) {
} catch (e, stackTrace) {
print('❌ Repository: Unexpected error - $e');
print('Stack trace: $stackTrace');
return Left(ServerFailure('Unexpected error: $e'));
}
}