Stop Autumn-only code paths throwing in local-ledger billing mode
Some checks failed
CI / ci (push) Has been cancelled
CI / docker-build (push) Has been cancelled
Publish Docker image / docker (push) Has been cancelled
Upload sourcemaps / upload (push) Has been cancelled

Two call sites still hard-required AUTUMN_SECRET_KEY regardless of billing
mode: the /api/autumn/$ route (autumn-js's client-side hooks hit it after
sign-up/on billing screens) and getBillingUsageEvents (Autumn's per-event
usage history). Both now degrade gracefully — 404 and an empty list,
respectively — when Autumn isn't configured, the same way subscription.ts's
credit checks already do, instead of autumn-js throwing "secret key not
found" once a request actually reaches it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
metatroncubeswdev 2026-10-17 21:31:30 -04:00
parent 78d0aaad0c
commit 9298f67c7f
2 changed files with 15 additions and 1 deletions

View File

@ -53,7 +53,13 @@ function loadHandler() {
} }
async function handleAutumnRequest(request: Request) { async function handleAutumnRequest(request: Request) {
if (!isHostedAuthMode(env.AUTH_MODE)) { // 404 in non-hosted modes, and also in hosted mode when Autumn isn't
// configured — a direct-Stripe deployment runs the local-ledger billing
// fallback instead (see subscription.ts) and has no Autumn customer to
// read, so this route has nothing to serve. Checking here, before
// loadHandler(), avoids autumn-js throwing "secret key not found" deep
// inside the handler once a client request reaches it.
if (!isHostedAuthMode(env.AUTH_MODE) || !env.AUTUMN_SECRET_KEY?.trim()) {
return new Response("Not found", { return new Response("Not found", {
status: 404, status: 404,
}); });

View File

@ -6,6 +6,7 @@ import {
} from "@/shared/billing"; } from "@/shared/billing";
import { AppError } from "@/server/lib/errors"; import { AppError } from "@/server/lib/errors";
import { import {
getOptionalEnvValue,
getRequiredEnvValue, getRequiredEnvValue,
isHostedServerAuthMode, isHostedServerAuthMode,
} from "@/server/lib/runtime-env"; } from "@/server/lib/runtime-env";
@ -61,6 +62,13 @@ export const getBillingUsageEvents = createServerFn({ method: "POST" })
return []; return [];
} }
// No Autumn behind this deployment (local-ledger billing fallback, see
// subscription.ts) — there's no per-event usage history to page through,
// just the running total the ledger keeps.
if (!(await getOptionalEnvValue("AUTUMN_SECRET_KEY"))) {
return [];
}
const events: BillingUsageEvent[] = []; const events: BillingUsageEvent[] = [];
let offset = 0; let offset = 0;