Add Stripe subscription status guard for /api/generate route #1534

Open
opened 2026-04-14 07:34:52 -04:00 by pook · 0 comments
Owner

Reject document generation requests from users with suspended or canceled subscriptions. This prevents free usage after subscription ends.

Requirements:

  1. Create src/middleware/require-active-subscription.ts
  2. Middleware logic:
    • Extract user ID from authenticated request (req.user.id)
    • Query stripe_subscriptions table for the user's latest subscription
    • If status is not 'active': return 403 { error: 'Active subscription required', subscriptionStatus: status }
    • If active: call next()
  3. Apply to POST /api/generate route (and only that route)
  4. Skip if no billing integration is configured (STRIPE_SECRET_KEY not set) — for dev mode
  5. Add test: mock user with canceled subscription → expect 403
  6. Add test: mock user with active subscription → expect next() called

Acceptance criteria:

  • Users with active subscription can generate documents
  • Users with canceled/past_due/trialing subscriptions get 403
  • Dev mode without Stripe config skips the check
  • Tests pass

Generated by CEO Planner (priority: 2)

Reject document generation requests from users with suspended or canceled subscriptions. This prevents free usage after subscription ends. Requirements: 1. Create src/middleware/require-active-subscription.ts 2. Middleware logic: - Extract user ID from authenticated request (req.user.id) - Query stripe_subscriptions table for the user's latest subscription - If status is not 'active': return 403 { error: 'Active subscription required', subscriptionStatus: status } - If active: call next() 3. Apply to POST /api/generate route (and only that route) 4. Skip if no billing integration is configured (STRIPE_SECRET_KEY not set) — for dev mode 5. Add test: mock user with canceled subscription → expect 403 6. Add test: mock user with active subscription → expect next() called Acceptance criteria: - Users with active subscription can generate documents - Users with canceled/past_due/trialing subscriptions get 403 - Dev mode without Stripe config skips the check - Tests pass --- *Generated by CEO Planner (priority: 2)*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/compliancebot#1534
No description provided.