Skip to content

Commit e42e6ef

Browse files
tofikwestclaude
andcommitted
fix(upgrade): keep self-hosted check on the page to avoid OSS regression
NEXT_PUBLIC_SELF_HOSTED is a Next.js build-time env that the OSS Docker deployment sets on the app container only — there is no propagation to the API container (the root docker-compose.yml ships only app + portal services). Moving the entire auto-approval flow into the API would have broken self-hosted/OSS deployments, since neither SELF_HOSTED nor NEXT_PUBLIC_SELF_HOSTED is available there. Restore the inline self-hosted branch on the upgrade page (preserves original behavior bit-for-bit) and route only the Stripe-customer + @trycomp.ai paths through the API. The single remaining DB write on the page is gated on a build-time deploy flag, not user input — so the "all mutations through the API" rule is preserved in spirit for every user-facing decision. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 250a392 commit e42e6ef

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

  • apps/app/src/app/(app)/upgrade/[orgId]

apps/app/src/app/(app)/upgrade/[orgId]/page.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { env } from '@/env.mjs';
12
import { serverApi } from '@/lib/api-server';
23
import { auth } from '@/utils/auth';
34
import { db } from '@db/server';
@@ -68,18 +69,33 @@ export default async function UpgradePage({ params }: PageProps) {
6869

6970
let hasAccess = member.organization.hasAccess;
7071

71-
// Auto-approval (self-hosted, trycomp emails, domain-matched Stripe customers)
72-
// is decided server-side by the API, which also persists hasAccess. Soft-fail
73-
// so a transient API error never blocks the booking step from rendering.
7472
if (!hasAccess) {
75-
const response = await serverApi.post<AutoApproveResponse>(
76-
'/v1/organization-access/auto-approve',
77-
);
78-
79-
if (response.data?.hasAccess) {
73+
// Self-hosted instances auto-approve every org. The flag is a Next.js
74+
// build-time env var (NEXT_PUBLIC_SELF_HOSTED) that the OSS Docker
75+
// deployment sets on the app container only — the API container does NOT
76+
// have this env, so the check stays on the page. The DB write here is the
77+
// single exception to "all mutations through the API" — it's gated on a
78+
// build-time deploy flag, not user input.
79+
if (env.NEXT_PUBLIC_SELF_HOSTED === 'true') {
80+
await db.organization.update({
81+
where: { id: orgId },
82+
data: { hasAccess: true },
83+
});
8084
hasAccess = true;
81-
} else if (response.error) {
82-
console.error('[UpgradePage] auto-approve API error:', response.error);
85+
} else {
86+
// Stripe-domain auto-approval (and the @trycomp.ai shortcut) live in the
87+
// API so STRIPE_SECRET_KEY only has to exist on the API and the
88+
// hasAccess flip is RBAC-checked + audit-logged. Soft-fail so a transient
89+
// API error never blocks the booking step from rendering.
90+
const response = await serverApi.post<AutoApproveResponse>(
91+
'/v1/organization-access/auto-approve',
92+
);
93+
94+
if (response.data?.hasAccess) {
95+
hasAccess = true;
96+
} else if (response.error) {
97+
console.error('[UpgradePage] auto-approve API error:', response.error);
98+
}
8399
}
84100
}
85101

0 commit comments

Comments
 (0)