fix : add cancel Token

This commit is contained in:
2025-06-23 10:42:29 +03:30
parent ec0e344e47
commit 1e3614ed58
10 changed files with 140 additions and 88 deletions

View File

@@ -1,11 +1,9 @@
import 'package:flutter/foundation.dart';
import 'package:rasadyar_auth/auth.dart';
import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart';
import 'package:rasadyar_core/core.dart';
import '../models/response/auth/auth_response_model.dart';
import '../services/token_storage_service.dart';
Future<void> safeCall<T>({
required AppAsyncCallback<T> call,
Function(T result)? onSuccess,
@@ -21,9 +19,6 @@ Future<void> safeCall<T>({
Function()? onShowSuccessMessage,
Function()? onShowErrorMessage,
}) {
final authRepository = diAuth.get<AuthRepositoryImpl>();
TokenStorageService tokenStorageService = Get.find<TokenStorageService>();
return gSafeCall(
call: call,
onSuccess: onSuccess,
@@ -38,24 +33,6 @@ Future<void> safeCall<T>({
onHideLoading: onHideLoading,
onShowSuccessMessage: onShowSuccessMessage,
onShowErrorMessage: onShowErrorMessage,
retryOnAuthError: true,
onTokenRefresh: () {
var token = tokenStorageService.refreshToken.value;
authRepository
.loginWithRefreshToken(authRequest: {"refresh_token": token})
.then((value) async {
if (value is AuthResponseModel) {
await tokenStorageService.saveAccessToken(value.access!);
} else {
throw Exception("Failed to refresh token");
}
})
.catchError((error) {
if (kDebugMode) {
print('Error during token refresh: $error');
}
throw error;
});
},
);
}