Login Repo

This commit is contained in:
efrilm
2025-09-18 07:04:06 +07:00
parent 1a0c0cf49b
commit b20854f329
9 changed files with 904 additions and 0 deletions
@@ -183,4 +183,44 @@ class AuthRemoteDataProvider {
return DC.error(AuthFailure.serverError(e));
}
}
Future<DC<AuthFailure, LoginDto>> login({
required String phoneNumber,
required String password,
}) async {
try {
final response = await _apiClient.post(
ApiPath.login,
data: {'phone_number': phoneNumber, 'password': password},
);
if (response.data['success'] == false) {
if ((response.data['errors'] as List).isNotEmpty) {
if (response.data['errors'][0]['code'] == "900") {
return DC.error(
AuthFailure.dynamicErrorMessage('Kamu Belum Terdaftar'),
);
} else {
return DC.error(
AuthFailure.dynamicErrorMessage(
'Terjadi kesalahan coba lagi nanti',
),
);
}
} else {
return DC.error(
AuthFailure.dynamicErrorMessage(
'Terjadi kesalahan coba lagi nanti',
),
);
}
}
final dto = LoginDto.fromJson(response.data['data']);
return DC.data(dto);
} on ApiFailure catch (e, s) {
log('login', name: _logName, error: e, stackTrace: s);
return DC.error(AuthFailure.serverError(e));
}
}
}