diff --git a/lib/controller/tenant/tenant_selection_controller.dart b/lib/controller/tenant/tenant_selection_controller.dart index b4cbee3..eb6f6a6 100644 --- a/lib/controller/tenant/tenant_selection_controller.dart +++ b/lib/controller/tenant/tenant_selection_controller.dart @@ -9,8 +9,6 @@ import 'package:marco/controller/permission_controller.dart'; class TenantSelectionController extends GetxController { final TenantService _tenantService = TenantService(); - TenantSelectionController(); - final tenants = [].obs; final isLoading = false.obs; final selectedTenantId = RxnString(); @@ -34,16 +32,13 @@ class TenantSelectionController extends GetxController { tenants.value = data.map((e) => Tenant.fromJson(e)).toList(); - // Smart auto-selection - final recentTenantId = await LocalStorage.getRecentTenantId(); + final recentTenantId = LocalStorage.getRecentTenantId(); if (tenants.length == 1) { await _selectTenant(tenants.first.id); } else if (recentTenantId != null) { - final recentTenant = - tenants.where((t) => t.id == recentTenantId).isNotEmpty - ? tenants.firstWhere((t) => t.id == recentTenantId) - : null; + final recentTenant = tenants + .firstWhereOrNull((t) => t.id == recentTenantId); if (recentTenant != null) { await _selectTenant(recentTenant.id); @@ -99,7 +94,7 @@ class TenantSelectionController extends GetxController { logSafe("✅ Tenant selection successful: $tenantId"); // 🔹 Load permissions after tenant selection (null-safe) - final token = await LocalStorage.getJwtToken(); + final token = LocalStorage.getJwtToken(); if (token != null && token.isNotEmpty) { if (!Get.isRegistered()) { Get.put(PermissionController()); @@ -107,7 +102,8 @@ class TenantSelectionController extends GetxController { } await Get.find().loadData(token); } else { - logSafe("⚠️ JWT token is null. Cannot load permissions.", level: LogLevel.warning); + logSafe("⚠️ JWT token is null. Cannot load permissions.", + level: LogLevel.warning); } // Navigate to dashboard diff --git a/lib/helpers/services/app_initializer.dart b/lib/helpers/services/app_initializer.dart index 45cd5c2..acd9b88 100644 --- a/lib/helpers/services/app_initializer.dart +++ b/lib/helpers/services/app_initializer.dart @@ -20,7 +20,7 @@ Future initializeApp() async { ]); await _setupDeviceInfo(); - await _handleAuthTokens(); // refresh token only, no controller injection + await _handleAuthTokens(); await _setupTheme(); await _setupFirebaseMessaging();