diff --git a/src/routes/api/autumn/$.ts b/src/routes/api/autumn/$.ts index ebb58b5..60adbc6 100644 --- a/src/routes/api/autumn/$.ts +++ b/src/routes/api/autumn/$.ts @@ -53,7 +53,13 @@ function loadHandler() { } 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", { status: 404, }); diff --git a/src/serverFunctions/billing.ts b/src/serverFunctions/billing.ts index 1b5b212..2b43136 100644 --- a/src/serverFunctions/billing.ts +++ b/src/serverFunctions/billing.ts @@ -6,6 +6,7 @@ import { } from "@/shared/billing"; import { AppError } from "@/server/lib/errors"; import { + getOptionalEnvValue, getRequiredEnvValue, isHostedServerAuthMode, } from "@/server/lib/runtime-env"; @@ -61,6 +62,13 @@ export const getBillingUsageEvents = createServerFn({ method: "POST" }) 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[] = []; let offset = 0;