refactor use cases
This commit is contained in:
@@ -2,7 +2,7 @@ import type { AuthCallbackCommand, AuthenticatedUser, IdentityProviderPort } fro
|
||||
import type { AuthSession, IdentitySessionPort } from '../ports/IdentitySessionPort';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort, Logger } from '@core/shared/application';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
|
||||
export type HandleAuthCallbackInput = AuthCallbackCommand;
|
||||
|
||||
@@ -20,19 +20,16 @@ export class HandleAuthCallbackUseCase {
|
||||
private readonly provider: IdentityProviderPort,
|
||||
private readonly sessionPort: IdentitySessionPort,
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<HandleAuthCallbackResult>,
|
||||
) {}
|
||||
|
||||
async execute(input: HandleAuthCallbackInput): Promise<
|
||||
Result<void, HandleAuthCallbackApplicationError>
|
||||
Result<HandleAuthCallbackResult, HandleAuthCallbackApplicationError>
|
||||
> {
|
||||
try {
|
||||
const user: AuthenticatedUser = await this.provider.completeAuth(input);
|
||||
const session = await this.sessionPort.createSession(user);
|
||||
|
||||
this.output.present(session);
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(session);
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof Error && error.message
|
||||
|
||||
Reference in New Issue
Block a user