/** * auth.routes.ts * * Rotas públicas e protegidas de autenticação: * POST /api/v1/auth/register → cria conta * POST /api/v1/auth/login → retorna JWT * GET /api/v1/auth/me → dados do usuário logado (protegida) */ import type { FastifyInstance } from 'fastify'; import { registerBodySchema, loginBodySchema, } from './auth.schema.js'; import { registerHandler, loginHandler, meHandler, } from './auth.controller.js'; async function authRoutes(fastify: FastifyInstance): Promise { // ── POST /auth/register ──────────────────────────────────────────────────── fastify.post('/register', { schema: { tags: ['Auth'], summary: 'Registra um novo usuário', body: registerBodySchema, }, handler: registerHandler, }); // ── POST /auth/login ─────────────────────────────────────────────────────── fastify.post('/login', { schema: { tags: ['Auth'], summary: 'Autentica e retorna um JWT', body: loginBodySchema, }, handler: loginHandler, }); // ── GET /auth/me ─────────────────────────────────────────────────────────── fastify.get('/me', { schema: { tags: ['Auth'], summary: 'Retorna o usuário autenticado', security: [{ bearerAuth: [] }], }, preHandler: [fastify.authenticate], handler: meHandler, }); } export default authRoutes;