From 3fc745737dabb875f8e6a129645f9599e7e63b90 Mon Sep 17 00:00:00 2001 From: "mr.mojtaba" Date: Sun, 29 Jun 2025 09:43:30 +0330 Subject: [PATCH] fix : don't redirect to login --- packages/auth/lib/data/utils/safe_call.dart | 2 -- .../lib/infrastructure/remote/app_interceptor.dart | 11 +++++++---- packages/core/lib/utils/network/safe_call_utils.dart | 3 +-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/auth/lib/data/utils/safe_call.dart b/packages/auth/lib/data/utils/safe_call.dart index fb14499..0e92be5 100644 --- a/packages/auth/lib/data/utils/safe_call.dart +++ b/packages/auth/lib/data/utils/safe_call.dart @@ -2,8 +2,6 @@ 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 safeCall({ required AppAsyncCallback call, Function(T result)? onSuccess, diff --git a/packages/core/lib/infrastructure/remote/app_interceptor.dart b/packages/core/lib/infrastructure/remote/app_interceptor.dart index c58cde5..7dff63a 100644 --- a/packages/core/lib/infrastructure/remote/app_interceptor.dart +++ b/packages/core/lib/infrastructure/remote/app_interceptor.dart @@ -1,4 +1,6 @@ import 'dart:async'; +import 'package:rasadyar_auth/presentation/routes/pages.dart'; + import '../../core.dart'; typedef RefreshTokenCallback = Future Function(); @@ -10,7 +12,7 @@ class AppInterceptor extends Interceptor { @override Future onError(DioException err, ErrorInterceptorHandler handler) async { if (err.response?.statusCode == 401 && !ApiHandler.isRefreshing) { - // اول بقیه درخواست‌ها رو کنسل کن + ApiHandler.cancelAllRequests("Token expired - refreshing"); ApiHandler.isRefreshing = true; @@ -19,7 +21,7 @@ class AppInterceptor extends Interceptor { final newToken = await refreshTokenCallback(); if (newToken == null) throw Exception("Refresh failed"); - // تولید CancelToken جدید برای درخواست‌های بعدی + ApiHandler.reset(); final opts = err.requestOptions; @@ -34,8 +36,9 @@ class AppInterceptor extends Interceptor { if (!ApiHandler.isRedirecting) { ApiHandler.isRedirecting = true; ApiHandler.cancelAllRequests("Cancel All Requests - Unauthorized"); - // TODO: Navigate to login - Get.offAllNamed('/login'); + if (Get.currentRoute != '/Auth') { + Get.offAllNamed('/Auth'); + } } handler.reject(err); } finally { diff --git a/packages/core/lib/utils/network/safe_call_utils.dart b/packages/core/lib/utils/network/safe_call_utils.dart index 7f51264..fca9f61 100644 --- a/packages/core/lib/utils/network/safe_call_utils.dart +++ b/packages/core/lib/utils/network/safe_call_utils.dart @@ -11,12 +11,11 @@ class ApiHandler { globalCancelToken = CancelToken(); } - // متد جدید برای کنسل کردن همه درخواست‌ها + static void cancelAllRequests(String reason) { if (!globalCancelToken.isCancelled) { globalCancelToken.cancel(reason); } - // CancelToken جدید بساز برای درخواست‌های بعدی globalCancelToken = CancelToken(); }