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
|
@override
|
||||||
Future<void> signOut() async {
|
Future<void> signOut() async {
|
||||||
try {
|
try {
|
||||||
await _service.auth.signOut();
|
await _service.signOut();
|
||||||
_service.clearCache();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Error signing out: ${e.toString()}');
|
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.
|
/// Clears Cached Repositories and Session data.
|
||||||
void clearCache() {
|
void _clearCache() {
|
||||||
_reportsRepository = null;
|
_reportsRepository = null;
|
||||||
_shiftsRepository = null;
|
_shiftsRepository = null;
|
||||||
_hubsRepository = null;
|
_hubsRepository = null;
|
||||||
|
|||||||
@@ -338,8 +338,7 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
|||||||
@override
|
@override
|
||||||
Future<void> signOut() async {
|
Future<void> signOut() async {
|
||||||
try {
|
try {
|
||||||
await _service.auth.signOut();
|
await _service.signOut();
|
||||||
_service.clearCache();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Error signing out: ${e.toString()}');
|
throw Exception('Error signing out: ${e.toString()}');
|
||||||
}
|
}
|
||||||
@@ -371,9 +370,7 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
|||||||
if (requireBusinessRole &&
|
if (requireBusinessRole &&
|
||||||
user.userRole != 'BUSINESS' &&
|
user.userRole != 'BUSINESS' &&
|
||||||
user.userRole != 'BOTH') {
|
user.userRole != 'BOTH') {
|
||||||
await _service.auth.signOut();
|
await _service.signOut();
|
||||||
dc.ClientSessionStore.instance.clear();
|
|
||||||
_service.clearCache();
|
|
||||||
throw UnauthorizedAppException(
|
throw UnauthorizedAppException(
|
||||||
technicalMessage:
|
technicalMessage:
|
||||||
'User role is ${user.userRole}, expected BUSINESS or BOTH',
|
'User role is ${user.userRole}, expected BUSINESS or BOTH',
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class SettingsRepositoryImpl implements SettingsRepositoryInterface {
|
|||||||
@override
|
@override
|
||||||
Future<void> signOut() async {
|
Future<void> signOut() async {
|
||||||
return _service.run(() 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.
|
/// Signs out the current user.
|
||||||
@override
|
@override
|
||||||
Future<void> signOut() {
|
Future<void> signOut() async {
|
||||||
StaffSessionStore.instance.clear();
|
return await _service.signOut();
|
||||||
_service.clearCache();
|
|
||||||
return _service.auth.signOut();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verifies an OTP code and returns the authenticated user.
|
/// Verifies an OTP code and returns the authenticated user.
|
||||||
@@ -163,7 +161,7 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
|||||||
|
|
||||||
if (staffResponse.data.staffs.isNotEmpty) {
|
if (staffResponse.data.staffs.isNotEmpty) {
|
||||||
// If profile exists, they should use Login mode.
|
// If profile exists, they should use Login mode.
|
||||||
await _service.auth.signOut();
|
await _service.signOut();
|
||||||
throw const domain.AccountExistsException(
|
throw const domain.AccountExistsException(
|
||||||
technicalMessage:
|
technicalMessage:
|
||||||
'This user already has a staff profile. Please log in.',
|
'This user already has a staff profile. Please log in.',
|
||||||
@@ -185,14 +183,14 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
await _service.auth.signOut();
|
await _service.signOut();
|
||||||
throw const domain.UserNotFoundException(
|
throw const domain.UserNotFoundException(
|
||||||
technicalMessage: 'Authenticated user profile not found in database.',
|
technicalMessage: 'Authenticated user profile not found in database.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Allow STAFF or BOTH roles to log in to the Staff App
|
// Allow STAFF or BOTH roles to log in to the Staff App
|
||||||
if (user.userRole != 'STAFF' && user.userRole != 'BOTH') {
|
if (user.userRole != 'STAFF' && user.userRole != 'BOTH') {
|
||||||
await _service.auth.signOut();
|
await _service.signOut();
|
||||||
throw const domain.UnauthorizedAppException(
|
throw const domain.UnauthorizedAppException(
|
||||||
technicalMessage: 'User is not authorized for this app.',
|
technicalMessage: 'User is not authorized for this app.',
|
||||||
);
|
);
|
||||||
@@ -206,7 +204,7 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
|||||||
requiresAuthentication: false,
|
requiresAuthentication: false,
|
||||||
);
|
);
|
||||||
if (staffResponse.data.staffs.isEmpty) {
|
if (staffResponse.data.staffs.isEmpty) {
|
||||||
await _service.auth.signOut();
|
await _service.signOut();
|
||||||
throw const domain.UserNotFoundException(
|
throw const domain.UserNotFoundException(
|
||||||
technicalMessage:
|
technicalMessage:
|
||||||
'Your account is not registered yet. Please register first.',
|
'Your account is not registered yet. Please register first.',
|
||||||
|
|||||||
Reference in New Issue
Block a user