fix : don't redirect to login
This commit is contained in:
@@ -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<void> safeCall<T>({
|
||||
required AppAsyncCallback<T> call,
|
||||
Function(T result)? onSuccess,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'package:rasadyar_auth/presentation/routes/pages.dart';
|
||||
|
||||
import '../../core.dart';
|
||||
|
||||
typedef RefreshTokenCallback = Future<String?> Function();
|
||||
@@ -10,7 +12,7 @@ class AppInterceptor extends Interceptor {
|
||||
@override
|
||||
Future<void> 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 {
|
||||
|
||||
@@ -11,12 +11,11 @@ class ApiHandler {
|
||||
globalCancelToken = CancelToken();
|
||||
}
|
||||
|
||||
// متد جدید برای کنسل کردن همه درخواستها
|
||||
|
||||
static void cancelAllRequests(String reason) {
|
||||
if (!globalCancelToken.isCancelled) {
|
||||
globalCancelToken.cancel(reason);
|
||||
}
|
||||
// CancelToken جدید بساز برای درخواستهای بعدی
|
||||
globalCancelToken = CancelToken();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user