Production/scripts/code_quality/check_route_auth_policy.ts
Ce check verifie que la politique d authentification API reste centralisee et coherente.
Objectif:
/api/v1 sans auth.src/routes/index.ts.apps/api/index.ts:/api/v1/health et /api/v1/openapi.json sont autorisees,authenticatedRoutes doit etre enregistre sur le prefixe /api/v1.apps/api/src/routes/index.ts:onRequest,x-service-token,401 Unauthorized en cas d echec,registerRoutes.src/routes/*.ts (hors index.ts et crud.ts) doit etre importe,fastify.register(...),onRequest local.Commande standard (depuis le dossier AM):
npm run check:route-auth-policy
[check:route-auth-policy] Starting API route auth policy validation
Project root: /mnt/data/vmenon/Other_Work/efrei-dev/AM
[OK] route auth policy is respected (0.00s).
[FAIL] route auth policy violations detected.
apps/api/index.ts:24 -> unexpected public /api/v1 route: GET /api/v1/users
apps/api/src/routes/index.ts:1 -> missing onRequest auth hook in routes index
Troubleshooting:
- Keep only /api/v1/health and /api/v1/openapi.json public in apps/api/index.ts.
- Register all /api/v1 business routes through authenticatedRoutes wrapper.
- Keep auth enforcement in apps/api/src/routes/index.ts onRequest hook.
- Re-run: npm run check:route-auth-policy
Summary: 2 violation(s) found in 0.01s.
x-service-token dans le hook central.src/routes/index.ts.