fix(billing): vercel cron not processing billing periods#1112
fix(billing): vercel cron not processing billing periods#1112icecrasher321 merged 1 commit intostagingfrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR fixes a critical issue preventing Vercel cron jobs from processing daily billing periods. The core problem was that Vercel's native cron system uses the x-vercel-cron: 1 header for authentication instead of custom Authorization headers, causing the existing Bearer token-only authentication to fail with 401 errors.
The fix involves two key changes:
-
Authentication Enhancement: The
verifyCronAuthfunction inapps/sim/lib/auth/internal.tsnow accepts both Vercel's native cron header (x-vercel-cron: 1) and the existing Bearer token authentication. This maintains backward compatibility while enabling Vercel cron jobs to authenticate successfully. -
Endpoint Consistency: The daily billing route (
apps/sim/app/api/billing/daily/route.ts) has been updated so that both GET and POST methods now execute theprocessDailyBillingCheck()function and return the same response structure. Previously, the GET endpoint was just a health check that returned a simple "OK" message.
The changes also include a minor bug fix in the error logging message, correcting "monthly" to "daily" billing cron job for accurate debugging information. This integration aligns with the existing billing infrastructure shown in the codebase context, where vercel.json configures a cron job to hit /api/schedules/execute every minute, and the authentication system in auth.ts manages various authentication methods.
Confidence score: 4/5
- This PR is safe to merge with low risk as it addresses a specific deployment issue
- Score reflects well-targeted changes that maintain backward compatibility while fixing a clear authentication problem
- Pay close attention to
apps/sim/lib/auth/internal.tsto ensure the dual authentication logic works correctly in production
2 files reviewed, no comments
Summary
Type of Change
Testing
Manually.
Checklist