/** * Login Mutation * * Framework-agnostic mutation for login operations. * Called from Server Actions. * * Pattern: Server Action → Mutation → Service → API Client */ import { Result } from '@/lib/contracts/Result'; import { AuthService } from '@/lib/services/auth/AuthService'; import { SessionViewModel } from '@/lib/view-models/SessionViewModel'; import { LoginParamsDTO } from '@/lib/types/generated/LoginParamsDTO'; export class LoginMutation { async execute(params: LoginParamsDTO): Promise> { try { const authService = new AuthService(); const result = await authService.login(params); if (result.isErr()) { return Result.err(result.getError().message); } return Result.ok(result.unwrap()); } catch (error: any) { const errorMessage = error instanceof Error ? error.message : 'Login failed'; return Result.err(errorMessage); } } }