From 2f91099c173936dec7f59b8d5e487a24437c4a89 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 6 Aug 2026 18:54:59 +0530 Subject: [PATCH] fix(billing): stop a zero seat limit turning free orgs read-only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `getServiceLimit('members')` returned `plan.addons.seats.limit ?? 1`. The Appwrite starter plan's seats addon omits `limit`, and the API serializes the missing value as `0` — which is not nullish, so the `?? 1` fallback never applied and the limit came back as `0`. `checkForUsageLimit` then read that as "no members allowed": membersOverflow = Math.max(0, organization.total - 0) // always >= 1 so every free-plan organization was flipped to read-only, which silently disables project creation, member invites and the other write actions gated on `readOnly`. The explanatory banner never showed either, because `limitReached.svelte` is gated on `!billingPlanDetails.usage` and the starter plan's `usage` serializes to a truthy object — leaving a greyed-out "Create project" button with no reason given. Normalise a zero limit to `Infinity` in `getServiceLimit` so every caller agrees, and only treat a real, positive cap as exceedable so a bad limit can't take an organization read-only again. The UI call sites already worked around this with `getServiceLimit('members', ...) || Infinity`; `checkForUsageLimit` was the only consumer that did not. Plans that set an explicit seat limit (the Imagine plans use 1) are unaffected, as are Pro, Scale and Education, which declare no seats addon and already returned `Infinity`. --- src/lib/stores/billing.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 7003d88bc..db1c57c98 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -277,7 +277,10 @@ export function getServiceLimit( if (serviceId === 'members') { if (!plan?.addons?.seats) return Infinity; - return plan.addons.seats?.limit ?? 1; + // Plans that don't cap seats omit `limit` in the plan config, and the API + // serializes the missing value as `0`. That means "no seat cap", not + // "no members allowed" — an organization always has at least one member. + return plan.addons.seats?.limit || Infinity; } if (serviceId === 'projects') { @@ -474,7 +477,11 @@ export async function checkForUsageLimit(organization: Models.Organization) { const members = organization.total; const memberLimit = getServiceLimit('members'); - const membersOverflow = memberLimit === Infinity ? 0 : Math.max(0, members - memberLimit); + // Only a real, positive cap can be exceeded. Without this guard an unknown or + // zero limit turns every organization read-only, which silently disables + // project creation, member invites and every other write action. + const membersOverflow = + Number.isFinite(memberLimit) && memberLimit > 0 ? Math.max(0, members - memberLimit) : 0; if (resources.some((r) => r.value >= 100) || membersOverflow > 0) { readOnly.set(true);