/** * auth.schema.ts * Schemas Zod para registro, login e resposta de usuário. */ import { z } from 'zod'; import { USER_ROLES } from '@/db/schema.js'; // ─── Registro ───────────────────────────────────────────────────────────────── export const registerBodySchema = z.object({ name: z .string({ required_error: 'Nome é obrigatório' }) .min(2, 'Nome deve ter no mínimo 2 caracteres') .max(100) .trim(), email: z .string({ required_error: 'E-mail é obrigatório' }) .email('E-mail inválido') .toLowerCase() .trim(), password: z .string({ required_error: 'Senha é obrigatória' }) .min(8, 'Senha deve ter no mínimo 8 caracteres') .max(100), // Somente admins podem criar agentes/admins — validado no controller role: z.enum(USER_ROLES).default('requester'), }); export type RegisterBody = z.infer; // ─── Login ──────────────────────────────────────────────────────────────────── export const loginBodySchema = z.object({ email: z .string({ required_error: 'E-mail é obrigatório' }) .email('E-mail inválido') .toLowerCase() .trim(), password: z.string({ required_error: 'Senha é obrigatória' }), }); export type LoginBody = z.infer; // ─── Shape de resposta (NUNCA inclui password) ──────────────────────────────── export const userResponseSchema = z.object({ id: z.number(), name: z.string(), email: z.string(), role: z.enum(USER_ROLES), isActive: z.boolean(), createdAt: z.string(), }); export const authResponseSchema = z.object({ token: z.string(), user: userResponseSchema, }); export type UserResponse = z.infer; export type AuthResponse = z.infer;