From e8b768b9788bd4f556f98ade3ede47fb4d7bd916 Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Mon, 2 Mar 2026 16:04:20 -0500 Subject: [PATCH] feat: Refactor sign-out method to use unified service call across repositories --- .../staff_connector_repository_impl.dart | 3 +-- .../lib/src/services/data_connect_service.dart | 13 ++++++++++++- .../repositories_impl/auth_repository_impl.dart | 7 ++----- .../settings_repository_impl.dart | 2 +- .../repositories_impl/auth_repository_impl.dart | 14 ++++++-------- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/apps/mobile/packages/data_connect/lib/src/connectors/staff/data/repositories/staff_connector_repository_impl.dart b/apps/mobile/packages/data_connect/lib/src/connectors/staff/data/repositories/staff_connector_repository_impl.dart index 0b679eb1..770f1d68 100644 --- a/apps/mobile/packages/data_connect/lib/src/connectors/staff/data/repositories/staff_connector_repository_impl.dart +++ b/apps/mobile/packages/data_connect/lib/src/connectors/staff/data/repositories/staff_connector_repository_impl.dart @@ -475,8 +475,7 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository { @override Future signOut() async { try { - await _service.auth.signOut(); - _service.clearCache(); + await _service.signOut(); } catch (e) { throw Exception('Error signing out: ${e.toString()}'); } diff --git a/apps/mobile/packages/data_connect/lib/src/services/data_connect_service.dart b/apps/mobile/packages/data_connect/lib/src/services/data_connect_service.dart index 8e79de80..4465a7cb 100644 --- a/apps/mobile/packages/data_connect/lib/src/services/data_connect_service.dart +++ b/apps/mobile/packages/data_connect/lib/src/services/data_connect_service.dart @@ -224,8 +224,19 @@ class DataConnectService with DataErrorHandler, SessionHandlerMixin { } } + /// Signs out the current user from Firebase Auth and clears all session data. + Future signOut() async { + try { + await auth.signOut(); + _clearCache(); + } catch (e) { + debugPrint('DataConnectService: Error signing out: $e'); + rethrow; + } + } + /// Clears Cached Repositories and Session data. - void clearCache() { + void _clearCache() { _reportsRepository = null; _shiftsRepository = null; _hubsRepository = null; diff --git a/apps/mobile/packages/features/client/authentication/lib/src/data/repositories_impl/auth_repository_impl.dart b/apps/mobile/packages/features/client/authentication/lib/src/data/repositories_impl/auth_repository_impl.dart index 511e6f15..3361b69d 100644 --- a/apps/mobile/packages/features/client/authentication/lib/src/data/repositories_impl/auth_repository_impl.dart +++ b/apps/mobile/packages/features/client/authentication/lib/src/data/repositories_impl/auth_repository_impl.dart @@ -338,8 +338,7 @@ class AuthRepositoryImpl implements AuthRepositoryInterface { @override Future signOut() async { try { - await _service.auth.signOut(); - _service.clearCache(); + await _service.signOut(); } catch (e) { throw Exception('Error signing out: ${e.toString()}'); } @@ -371,9 +370,7 @@ class AuthRepositoryImpl implements AuthRepositoryInterface { if (requireBusinessRole && user.userRole != 'BUSINESS' && user.userRole != 'BOTH') { - await _service.auth.signOut(); - dc.ClientSessionStore.instance.clear(); - _service.clearCache(); + await _service.signOut(); throw UnauthorizedAppException( technicalMessage: 'User role is ${user.userRole}, expected BUSINESS or BOTH', diff --git a/apps/mobile/packages/features/client/settings/lib/src/data/repositories_impl/settings_repository_impl.dart b/apps/mobile/packages/features/client/settings/lib/src/data/repositories_impl/settings_repository_impl.dart index 2da4bc85..7acb21ad 100644 --- a/apps/mobile/packages/features/client/settings/lib/src/data/repositories_impl/settings_repository_impl.dart +++ b/apps/mobile/packages/features/client/settings/lib/src/data/repositories_impl/settings_repository_impl.dart @@ -15,7 +15,7 @@ class SettingsRepositoryImpl implements SettingsRepositoryInterface { @override Future signOut() async { return _service.run(() async { - await _service.auth.signOut(); + await _service.signOut(); }); } } diff --git a/apps/mobile/packages/features/staff/authentication/lib/src/data/repositories_impl/auth_repository_impl.dart b/apps/mobile/packages/features/staff/authentication/lib/src/data/repositories_impl/auth_repository_impl.dart index 7b6bc1bc..e9e7f1c7 100644 --- a/apps/mobile/packages/features/staff/authentication/lib/src/data/repositories_impl/auth_repository_impl.dart +++ b/apps/mobile/packages/features/staff/authentication/lib/src/data/repositories_impl/auth_repository_impl.dart @@ -96,10 +96,8 @@ class AuthRepositoryImpl implements AuthRepositoryInterface { /// Signs out the current user. @override - Future signOut() { - StaffSessionStore.instance.clear(); - _service.clearCache(); - return _service.auth.signOut(); + Future signOut() async { + return await _service.signOut(); } /// Verifies an OTP code and returns the authenticated user. @@ -163,7 +161,7 @@ class AuthRepositoryImpl implements AuthRepositoryInterface { if (staffResponse.data.staffs.isNotEmpty) { // If profile exists, they should use Login mode. - await _service.auth.signOut(); + await _service.signOut(); throw const domain.AccountExistsException( technicalMessage: 'This user already has a staff profile. Please log in.', @@ -185,14 +183,14 @@ class AuthRepositoryImpl implements AuthRepositoryInterface { } } else { if (user == null) { - await _service.auth.signOut(); + await _service.signOut(); throw const domain.UserNotFoundException( technicalMessage: 'Authenticated user profile not found in database.', ); } // Allow STAFF or BOTH roles to log in to the Staff App if (user.userRole != 'STAFF' && user.userRole != 'BOTH') { - await _service.auth.signOut(); + await _service.signOut(); throw const domain.UnauthorizedAppException( technicalMessage: 'User is not authorized for this app.', ); @@ -206,7 +204,7 @@ class AuthRepositoryImpl implements AuthRepositoryInterface { requiresAuthentication: false, ); if (staffResponse.data.staffs.isEmpty) { - await _service.auth.signOut(); + await _service.signOut(); throw const domain.UserNotFoundException( technicalMessage: 'Your account is not registered yet. Please register first.',