diff options
Diffstat (limited to 'api/src/modules/auth/auth.routes.ts')
| -rw-r--r-- | api/src/modules/auth/auth.routes.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/api/src/modules/auth/auth.routes.ts b/api/src/modules/auth/auth.routes.ts new file mode 100644 index 0000000..1de0e16 --- /dev/null +++ b/api/src/modules/auth/auth.routes.ts @@ -0,0 +1,55 @@ +/** + * 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<void> { + + // ── 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; |