Replaces the no-op fastify.authenticate stub and the never-implemented
identity/auth login with real bcrypt password verification, JWT session
issuance/verification (reusing the existing JWT_SECRET), and a Redis-backed
revocation denylist for logout. Adds requireRole('ADMIN') to admin-only
configuration writes across 002-009 that previously relied on a decorator
that never actually checked anything. Adds self-identity (GET /auth/me,
re-validated against live account state) and admin-provisioned accounts
(POST /admin/users).
Making the auth check genuinely reject invalid/missing tokens exposed that
~18 pre-existing integration test files called already-gated routes with no
Authorization header (safe against the old no-op stub, broken against a real
one) — fixed via a shared tests/helpers/auth.ts (loginAs/authHeader) and a
file-by-file pass, plus two related SLA-run cleanup races exposed once admin
setup calls in those files' own beforeAll blocks started actually succeeding.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
import { FastifyInstance } from 'fastify';
|
|
import { requireRole } from '@/modules/identity/auth';
|
|
import { agentsController } from '../controller';
|
|
|
|
/** Admin routes gated by fastify.authenticate — real as of 010-identity-auth (previously a
|
|
* no-op stub, per that feature's own research.md). `POST /admin/users` additionally requires
|
|
* the ADMIN role (010's own User Story 4) since account creation is more sensitive than
|
|
* agent-roster management. */
|
|
export async function agentsRoutes(fastify: FastifyInstance): Promise<void> {
|
|
fastify.post(
|
|
'/admin/users',
|
|
{ preHandler: [fastify.authenticate, requireRole('ADMIN')] },
|
|
(req, reply) => agentsController.createUser(req, reply),
|
|
);
|
|
fastify.post('/admin/teams/:teamId/agents', { preHandler: fastify.authenticate }, (req, reply) =>
|
|
agentsController.create(req, reply),
|
|
);
|
|
fastify.patch('/admin/agents/:agentId', { preHandler: fastify.authenticate }, (req, reply) =>
|
|
agentsController.update(req, reply),
|
|
);
|
|
fastify.get('/admin/agents/:agentId', { preHandler: fastify.authenticate }, (req, reply) =>
|
|
agentsController.getById(req, reply),
|
|
);
|
|
fastify.get('/admin/agents', { preHandler: fastify.authenticate }, (req, reply) =>
|
|
agentsController.list(req, reply),
|
|
);
|
|
|
|
fastify.put(
|
|
'/admin/agents/:agentId/skills/:skillTag',
|
|
{ preHandler: fastify.authenticate },
|
|
(req, reply) => agentsController.upsertSkill(req, reply),
|
|
);
|
|
fastify.get('/admin/agents/:agentId/skills', { preHandler: fastify.authenticate }, (req, reply) =>
|
|
agentsController.listSkills(req, reply),
|
|
);
|
|
|
|
fastify.put(
|
|
'/admin/agents/:agentId/availability',
|
|
{ preHandler: fastify.authenticate },
|
|
(req, reply) => agentsController.upsertAvailability(req, reply),
|
|
);
|
|
fastify.get(
|
|
'/admin/agents/:agentId/availability',
|
|
{ preHandler: fastify.authenticate },
|
|
(req, reply) => agentsController.getAvailability(req, reply),
|
|
);
|
|
}
|