Files
gridpilot.gg/packages/application/use-cases/VerifyAuthenticatedPageUseCase.ts
2025-11-26 17:03:29 +01:00

37 lines
1.2 KiB
TypeScript

import { IAuthenticationService } from '../ports/IAuthenticationService';
import { Result } from '../../shared/result/Result';
import { BrowserAuthenticationState } from '../../domain/value-objects/BrowserAuthenticationState';
/**
* Use case for verifying browser shows authenticated page state.
* Combines cookie validation with page content verification.
*/
export class VerifyAuthenticatedPageUseCase {
constructor(
private readonly authService: IAuthenticationService
) {}
async execute(): Promise<Result<BrowserAuthenticationState>> {
try {
const result = await this.authService.verifyPageAuthentication();
if (result.isErr()) {
return Result.err(result.error);
}
const browserState = result.unwrap();
// Log verification result
if (browserState.isFullyAuthenticated()) {
// Success case - no logging needed in use case
} else if (browserState.requiresReauthentication()) {
// Requires re-auth - caller should handle
}
return Result.ok(browserState);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
return Result.err(new Error(`Page verification failed: ${message}`));
}
}
}