fixed auto tenant selection

This commit is contained in:
Vaibhav Surve 2025-10-08 11:41:38 +05:30
parent 7e75431feb
commit d1d48b1a74
2 changed files with 7 additions and 11 deletions

View File

@ -9,8 +9,6 @@ import 'package:marco/controller/permission_controller.dart';
class TenantSelectionController extends GetxController {
final TenantService _tenantService = TenantService();
TenantSelectionController();
final tenants = <Tenant>[].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<PermissionController>()) {
Get.put(PermissionController());
@ -107,7 +102,8 @@ class TenantSelectionController extends GetxController {
}
await Get.find<PermissionController>().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

View File

@ -20,7 +20,7 @@ Future<void> initializeApp() async {
]);
await _setupDeviceInfo();
await _handleAuthTokens(); // refresh token only, no controller injection
await _handleAuthTokens();
await _setupTheme();
await _setupFirebaseMessaging();