Files
mcpctl/src/mcpd/src/routes/auth.ts
Michal b8c5cf718a
Some checks failed
CI / lint (pull_request) Has been cancelled
CI / typecheck (pull_request) Has been cancelled
CI / test (pull_request) Has been cancelled
CI / build (pull_request) Has been cancelled
CI / package (pull_request) Has been cancelled
feat: implement v2 3-tier architecture (mcpctl → mcplocal → mcpd)
- Rename local-proxy to mcplocal with HTTP server, LLM pipeline, mcpd discovery
- Add LLM pre-processing: token estimation, filter cache, metrics, Gemini CLI + DeepSeek providers
- Add mcpd auth (login/logout) and MCP proxy endpoints
- Update CLI: dual URLs (mcplocalUrl/mcpdUrl), auth commands, --direct flag
- Add tiered health monitoring, shell completions, e2e integration tests
- 57 test files, 597 tests passing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 11:42:06 +00:00

32 lines
1.1 KiB
TypeScript

import type { FastifyInstance } from 'fastify';
import type { AuthService } from '../services/auth.service.js';
import { createAuthMiddleware } from '../middleware/auth.js';
export interface AuthRouteDeps {
authService: AuthService;
}
export function registerAuthRoutes(app: FastifyInstance, deps: AuthRouteDeps): void {
const authMiddleware = createAuthMiddleware({
findSession: (token) => deps.authService.findSession(token),
});
// POST /api/v1/auth/login — no auth required
app.post<{
Body: { email: string; password: string };
}>('/api/v1/auth/login', async (request) => {
const { email, password } = request.body;
const result = await deps.authService.login(email, password);
return result;
});
// POST /api/v1/auth/logout — auth required
app.post('/api/v1/auth/logout', { preHandler: [authMiddleware] }, async (request) => {
const header = request.headers.authorization;
// Auth middleware already validated the header; extract the token
const token = header!.slice(7);
await deps.authService.logout(token);
return { success: true };
});
}