import { Result } from '../../../shared/result/Result'; import type { AuthenticationServicePort } from '../ports/AuthenticationServicePort'; import type { ILogger } from '../../../shared/src/logging/ILogger'; /** * Use case for clearing the user's session (logout). * * Removes stored browser context and cookies, effectively logging * the user out. The next automation attempt will require re-authentication. */ export class ClearSessionUseCase { constructor( private readonly authService: AuthenticationServicePort, private readonly logger: ILogger, // Inject ILogger ) {} /** * Execute the session clearing. * * @returns Result indicating success or failure */ async execute(): Promise> { this.logger.debug('Attempting to clear user session.', { useCase: 'ClearSessionUseCase' }); try { const result = await this.authService.clearSession(); if (result.isSuccess) { this.logger.info('User session cleared successfully.', { useCase: 'ClearSessionUseCase' }); } else { this.logger.warn('Failed to clear user session.', { useCase: 'ClearSessionUseCase', error: result.error, }); } return result; } catch (error: any) { this.logger.error('Error clearing user session.', error, { useCase: 'ClearSessionUseCase' }); return Result.fail(error.message); } } }