diff options
| author | zwlucas <lucas.fariamo08@gmail.com> | 2026-07-25 21:23:29 +0000 |
|---|---|---|
| committer | zwlucas <lucas.fariamo08@gmail.com> | 2026-07-25 21:23:29 +0000 |
| commit | ef55d9bb24430610b60c1b77821307cd72c08c55 (patch) | |
| tree | e6935a810b34370b0a4c821e55f6397aac50c832 /api/src/modules/auth/auth.schema.ts | |
| download | helpdesk-ef55d9bb24430610b60c1b77821307cd72c08c55.tar.gz helpdesk-ef55d9bb24430610b60c1b77821307cd72c08c55.zip | |
Signed-off-by: zwlucas <lucas.fariamo08@gmail.com>
Diffstat (limited to 'api/src/modules/auth/auth.schema.ts')
| -rw-r--r-- | api/src/modules/auth/auth.schema.ts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/api/src/modules/auth/auth.schema.ts b/api/src/modules/auth/auth.schema.ts new file mode 100644 index 0000000..7c9e8cd --- /dev/null +++ b/api/src/modules/auth/auth.schema.ts @@ -0,0 +1,66 @@ +/** + * 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<typeof registerBodySchema>; + +// ─── 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<typeof loginBodySchema>; + +// ─── 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<typeof userResponseSchema>; +export type AuthResponse = z.infer<typeof authResponseSchema>; |