feat: Refactor sign-out method to use unified service call across repositories
This commit is contained in:
@@ -475,8 +475,7 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
@override
|
||||
Future<void> signOut() async {
|
||||
try {
|
||||
await _service.auth.signOut();
|
||||
_service.clearCache();
|
||||
await _service.signOut();
|
||||
} catch (e) {
|
||||
throw Exception('Error signing out: ${e.toString()}');
|
||||
}
|
||||
|
||||
@@ -224,8 +224,19 @@ class DataConnectService with DataErrorHandler, SessionHandlerMixin {
|
||||
}
|
||||
}
|
||||
|
||||
/// Signs out the current user from Firebase Auth and clears all session data.
|
||||
Future<void> 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;
|
||||
|
||||
@@ -338,8 +338,7 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
||||
@override
|
||||
Future<void> 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',
|
||||
|
||||
@@ -15,7 +15,7 @@ class SettingsRepositoryImpl implements SettingsRepositoryInterface {
|
||||
@override
|
||||
Future<void> signOut() async {
|
||||
return _service.run(() async {
|
||||
await _service.auth.signOut();
|
||||
await _service.signOut();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,10 +96,8 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
||||
|
||||
/// Signs out the current user.
|
||||
@override
|
||||
Future<void> signOut() {
|
||||
StaffSessionStore.instance.clear();
|
||||
_service.clearCache();
|
||||
return _service.auth.signOut();
|
||||
Future<void> 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.',
|
||||
|
||||
Reference in New Issue
Block a user