1745265fe3
- Add validatePortalSession middleware (apps/api/src/middleware/portalSession.ts)
- Reads X-Impersonation-Session-Id header
- Queries impersonationSessions for active session with status='active'
- Validates expiresAt > new Date() (strict >, consistent everywhere)
- Sets portalClientId and portalSessionId on Hono context
- Returns 401 Unauthorized for missing/invalid/expired sessions
- Add portalAuditMiddleware (apps/api/src/middleware/portalAudit.ts)
- Runs after validatePortalSession via middleware chain
- Inserts impersonationAuditLogs entry on all portal requests
- action: 'METHOD /path', pageVisited: c.req.path, metadata: { method, statusCode }
- Swallows errors (logs to console, does not break user request)
- Apply middleware to all portal routes in portal.ts
- Replace all 11 getClientIdFromSession() calls with c.get('portalClientId')
- Replace 3 inline session queries in waitlist routes (POST/PATCH/DELETE)
- Remove getClientIdFromSession() helper (no longer needed)
- Remove unused 'and' import
- Add portalSession.test.ts with tests for validatePortalSession and portalAuditMiddleware
Co-Authored-By: Paperclip <noreply@paperclip.ing>