import { InputParseError } from "../../entities/errors/common"; import { signInInputSchema, type ISignInUseCase, type SignInOutput, type SignInRequestContext, } from "../../application/use-cases/sign-in.use-case"; function presenter(value: SignInOutput) { return value.cookie; } export type ISignInController = ReturnType; export const signInController = (signInUseCase: ISignInUseCase) => async ( input: unknown, // Server-derived, never part of the client-facing input schema (B2): // the tRPC adapter builds it from trusted proxy headers. requestContext?: SignInRequestContext, ): Promise> => { const parsed = signInInputSchema.safeParse(input); if (!parsed.success) { throw new InputParseError("Invalid sign-in input", { cause: parsed.error, }); } const result = await signInUseCase({ ...parsed.data, clientIp: requestContext?.clientIp, }); return presenter(result); };