feat : auth for new module

This commit is contained in:
MrM
2025-06-03 22:52:21 +03:30
parent ae18a5f648
commit 2b4c019c55
16 changed files with 314 additions and 133 deletions

View File

@@ -5,10 +5,14 @@ class DioErrorHandler {
void handle(DioException error) {
switch (error.response?.statusCode) {
case 401:
_handle401();
_handleGeneric(error);
break;
case 403:
_handle403();
_handleGeneric(error);
break;
case 410:
_handle410();
break;
default:
_handleGeneric(error);
@@ -16,21 +20,22 @@ class DioErrorHandler {
}
//wrong password/user name => "detail": "No active account found with the given credentials" - 401
void _handle401() {
Get.showSnackbar(
_errorSnackBar('نام کاربری یا رمز عبور اشتباه است'),
);
void _handle410() {
Get.showSnackbar(_errorSnackBar('نام کاربری یا رمز عبور اشتباه است'));
}
//wrong captcha => "detail": "Captcha code is incorrect" - 403
void _handle403() {
Get.showSnackbar(
_errorSnackBar('کد امنیتی اشتباه است'),
);
}
void _handle403() {}
void _handleGeneric(DioException error) {
// General error handling
Get.showSnackbar(
_errorSnackBar(
error.response?.data.keys.first == 'is_user'
? 'کاربر با این شماره تلفن وجود ندارد'
: error.response?.data[error.response?.data.keys.first] ??
'خطا در برقراری ارتباط با سرور',
),
);
}
GetSnackBar _errorSnackBar(String message) {

View File

@@ -12,7 +12,7 @@ class DioRemoteManager {
ApiEnvironment env = ApiEnvironment.dam,
]) async {
if (_currentEnv != env) {
_currentClient = DioRemote(env.baseUrl);
_currentClient = DioRemote(baseUrl: env.baseUrl);
await _currentClient?.init();
_currentEnv = env;
}