feat : login api call

This commit is contained in:
2025-05-17 15:24:06 +03:30
parent 0e630e709b
commit 303ff86d85
22 changed files with 518 additions and 522 deletions

View File

@@ -14,64 +14,34 @@ class AuthRepositoryImpl implements AuthRepository {
Future<AuthResponseModel?> login({
required Map<String, dynamic> authRequest,
}) async {
final response = await safeCall<DioResponse<AuthResponseModel>>(
call:
() async => await _httpClient.post<AuthResponseModel>(
'$_BASE_URL/login/',
data: authRequest,
headers: {'Content-Type': 'application/json'},
),
onSuccess: (response) {
iLog(response);
},
onError: (error, trace) {
throw Exception('Error during sign in: $error');
},
var res = await _httpClient.post<AuthResponseModel>(
'$_BASE_URL/login/',
data: authRequest,
fromJson: AuthResponseModel.fromJson,
headers: {'Content-Type': 'application/json'},
);
return response?.data;
return res.data;
}
@override
Future<CaptchaResponseModel?> captcha() async {
final response = await safeCall<CaptchaResponseModel?>(
call: () async {
var res = await _httpClient.post<CaptchaResponseModel?>(
'captcha/',
fromJson: CaptchaResponseModel.fromJson,
);
return res.data;
},
onSuccess: (response) {
return response;
},
onError: (error, trace) {
throw Exception('Error during captcha : $error');
},
var res = await _httpClient.post<CaptchaResponseModel?>(
'captcha/',
fromJson: CaptchaResponseModel.fromJson,
);
return response;
return res.data;
}
@override
Future<AuthResponseModel?> loginWithRefreshToken({
required Map<String, dynamic> authRequest,
}) async {
final response = await safeCall<DioResponse<AuthResponseModel>>(
call:
() async => await _httpClient.post<AuthResponseModel>(
'$_BASE_URL/login/',
data: authRequest,
headers: {'Content-Type': 'application/json'},
),
onSuccess: (response) {
iLog(response);
},
onError: (error, trace) {
throw Exception('Error during sign in: $error');
},
var res = await _httpClient.post<AuthResponseModel>(
'$_BASE_URL/login/',
data: authRequest,
headers: {'Content-Type': 'application/json'},
);
return response?.data;
return res.data;
}
@override
@@ -82,20 +52,11 @@ class AuthRepositoryImpl implements AuthRepository {
@override
Future<bool> hasAuthenticated() async {
final response = await safeCall<DioResponse<bool>>(
call:
() async => await _httpClient.get<bool>(
'$_BASE_URL/login/',
headers: {'Content-Type': 'application/json'},
),
onSuccess: (response) {
iLog(response);
},
onError: (error, trace) {
throw Exception('Error during sign in: $error');
},
final response = await _httpClient.get<bool>(
'$_BASE_URL/login/',
headers: {'Content-Type': 'application/json'},
);
return response?.data ?? false;
return response.data ?? false;
}
}