import 'package:getx_scaffold/common/index.dart';
import 'package:ln_jq_app/pages/login/view.dart';
import 'package:ln_jq_app/storage_service.dart';

class AuthGuard {
  static bool _handling401 = false;

  static Future<void> handle401(String? message) async {
    if (_handling401) return;
    _handling401 = true;

    try {
      await StorageService.to.clearLoginInfo();
      Get.offAll(() => const LoginPage());
    } finally {
      // 防止意外卡死，可视情况是否延迟重置
      Future.delayed(const Duration(seconds: 1), () {
        _handling401 = false;
      });
    }
  }
}
