Skip to content

Commit bac9d80

Browse files
committed
feat(auth): Implement token invalidation on sign out
- Invalidates token via AuthTokenService - Adds token parameter to performSignOut - Throws OperationFailedException on failure
1 parent bb4340b commit bac9d80

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

lib/src/services/auth_service.dart

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,37 +192,42 @@ class AuthService {
192192
/// The primary client-side action (clearing the local token) is handled
193193
/// separately by the client application.
194194
///
195-
/// Throws: This implementation currently does not throw exceptions under
196-
/// normal circumstances. Future implementations involving token
197-
/// invalidation might throw [OperationFailedException] if invalidation fails.
198-
Future<void> performSignOut({required String userId}) async {
199-
// Log the attempt.
195+
/// Performs server-side sign-out actions, including token invalidation.
196+
///
197+
/// Invalidates the provided authentication [token] using the
198+
/// [AuthTokenService].
199+
///
200+
/// The primary client-side action (clearing the local token) is handled
201+
/// separately by the client application.
202+
///
203+
/// Throws [OperationFailedException] if token invalidation fails.
204+
Future<void> performSignOut({
205+
required String userId,
206+
required String token,
207+
}) async {
200208
print(
201209
'[AuthService] Received request for server-side sign-out actions '
202210
'for user $userId.',
203211
);
204212

205-
// --- Placeholder for Future Token Invalidation ---
206-
// If AuthTokenService had an invalidateToken method, it would be called here:
207-
// try {
208-
// // Assuming the token itself or its JTI was passed or derivable
209-
// // String tokenToInvalidate = ...;
210-
// // await _authTokenService.invalidateToken(tokenToInvalidate);
211-
// print('[AuthService] Token invalidation logic executed (if implemented).');
212-
// } catch (e) {
213-
// print('[AuthService] Error during token invalidation for user $userId: $e');
214-
// // Decide whether to rethrow or just log
215-
// // throw OperationFailedException('Failed server-side sign-out: $e');
216-
// }
217-
// ------------------------------------------------
218-
219-
// Simulate potential async work if needed in the future.
220-
await Future<void>.delayed(Duration.zero);
213+
try {
214+
// Invalidate the token using the AuthTokenService
215+
await _authTokenService.invalidateToken(token);
216+
print('[AuthService] Token invalidation logic executed for user $userId.');
217+
} on HtHttpException catch (_) {
218+
// Propagate known exceptions from the token service
219+
rethrow;
220+
} catch (e) {
221+
// Catch unexpected errors during token invalidation
222+
print('[AuthService] Error during token invalidation for user $userId: $e');
223+
throw OperationFailedException(
224+
'Failed server-side sign-out: Token invalidation failed.',
225+
);
226+
}
221227

222228
print(
223229
'[AuthService] Server-side sign-out actions complete for user $userId.',
224230
);
225-
// No specific exceptions are thrown in this placeholder implementation.
226231
}
227232

228233
/// Initiates the process of linking an [emailToLink] to an existing

0 commit comments

Comments
 (0)