fixed auto tenant selection
This commit is contained in:
parent
7e75431feb
commit
d1d48b1a74
@ -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
|
||||
|
@ -20,7 +20,7 @@ Future<void> initializeApp() async {
|
||||
]);
|
||||
|
||||
await _setupDeviceInfo();
|
||||
await _handleAuthTokens(); // refresh token only, no controller injection
|
||||
await _handleAuthTokens();
|
||||
await _setupTheme();
|
||||
await _setupFirebaseMessaging();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user