diff --git a/apps/mobile/packages/features/client/hubs/lib/src/data/repositories_impl/hub_repository_impl.dart b/apps/mobile/packages/features/client/hubs/lib/src/data/repositories_impl/hub_repository_impl.dart index 1fee40f5..3de1e29a 100644 --- a/apps/mobile/packages/features/client/hubs/lib/src/data/repositories_impl/hub_repository_impl.dart +++ b/apps/mobile/packages/features/client/hubs/lib/src/data/repositories_impl/hub_repository_impl.dart @@ -79,6 +79,30 @@ class HubRepositoryImpl implements HubRepositoryInterface { } Future _getBusinessForCurrentUser() async { + final session = dc.ClientSessionStore.instance.session; + final cachedBusiness = session?.business; + if (cachedBusiness != null) { + return dc.GetBusinessesByUserIdBusinesses( + id: cachedBusiness.id, + businessName: cachedBusiness.businessName, + userId: _firebaseAuth.currentUser?.uid ?? '', + rateGroup: dc.Known(dc.BusinessRateGroup.STANDARD), + status: dc.Known(dc.BusinessStatus.ACTIVE), + contactName: cachedBusiness.contactName, + companyLogoUrl: cachedBusiness.companyLogoUrl, + phone: null, + email: cachedBusiness.email, + hubBuilding: null, + address: null, + city: cachedBusiness.city, + area: null, + sector: null, + notes: null, + createdAt: null, + updatedAt: null, + ); + } + final user = _firebaseAuth.currentUser; if (user == null) { throw Exception('User is not authenticated.'); @@ -92,7 +116,25 @@ class HubRepositoryImpl implements HubRepositoryInterface { throw Exception('No business found for this user. Please sign in again.'); } - return result.data.businesses.first; + final business = result.data.businesses.first; + if (session != null) { + dc.ClientSessionStore.instance.setSession( + dc.ClientSession( + user: session.user, + userPhotoUrl: session.userPhotoUrl, + business: dc.ClientBusinessSession( + id: business.id, + businessName: business.businessName, + email: business.email, + city: business.city, + contactName: business.contactName, + companyLogoUrl: business.companyLogoUrl, + ), + ), + ); + } + + return business; } Future _getOrCreateTeamId(