fix(pdf): let PdfService reach the export route past auth middleware #127
No reviewers
Labels
No labels
bug
claude-failed
claude-pr
claude-queue
claude-working
epic
feature
interactive
portal
triaged
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: shad0w/pelagia-portal#127
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/pdf-export-middleware"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes the blocker found while enabling the PDF microservice on pms1: even with
PDF_SERVICE_URL+PDF_SERVICE_TOKENset and the service healthy, "Email PO to vendor" could never render a real PDF.Root cause
PdfService fetches
/api/po/<id>/export?...&svc=<token>without a user session, authenticating with asvctoken equal toPDF_SERVICE_TOKEN. The route handler validates that token — butmiddleware.tsruns first, and its matcher doesn't exempt the export route, so every unauthenticated fetch is redirected to/login(307) and thesvcbypass never runs. Confirmed on pms1: the export route returned 307 for the correct token on both the local and public host.Fix
Middleware now lets only
/api/po/<id>/exportthrough when itssvcparam matchesprocess.env.PDF_SERVICE_TOKEN; everything else stays auth-gated, and the route handler still re-validates the token (defense in depth). The matching logic is a dependency-free, edge-safe, unit-tested helper (lib/pdf-export-auth.ts). Middleware already reads server env at runtime viaauth()(NEXTAUTH_SECRET), so readingPDF_SERVICE_TOKENthere is consistent.Verification (running build, local dev)
svc+ real PO → 200svc+ bogus PO → 404 (handler ran, not redirected)svc→ 307 (still gated)tscclean; 324 unit tests green (+3 for the helper)Deploy note
The pms1 env is already configured (
PDF_SERVICE_URL,PDF_SERVICE_TOKEN,APP_INTERNAL_URL=http://localhost:3000) and pdf-service is live on :3005 with the matching token. Once this merges and a release tag deploys, "Email to vendor" should work end-to-end on prod.🤖 Generated with Claude Code