From c6a1bfeae187185508dd4226ccacf7ad2853cd29 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Wed, 20 May 2026 18:24:19 +0530 Subject: [PATCH 1/2] Fix billing null guards --- .../billing/alerts/newDevUpgradePro.svelte | 2 +- src/lib/components/tab.svelte | 5 +++++ src/lib/layout/containerHeader.svelte | 2 +- src/lib/stores/billing.ts | 14 ++++++++++---- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/lib/components/billing/alerts/newDevUpgradePro.svelte b/src/lib/components/billing/alerts/newDevUpgradePro.svelte index 7d38ec049c..b4b0254b3a 100644 --- a/src/lib/components/billing/alerts/newDevUpgradePro.svelte +++ b/src/lib/components/billing/alerts/newDevUpgradePro.svelte @@ -23,7 +23,7 @@ } -{#if show && $organization?.$id && !$organization?.billingPlanDetails.supportsCredits && !page.url.pathname.includes(base + '/account')} +{#if show && $organization?.$id && !$organization?.billingPlanDetails?.supportsCredits && !page.url.pathname.includes(base + '/account')} 0} + {@const supportsUsage = Object.keys($currentPlan?.usage ?? {}).length > 0} a.order - b.order)[0]; } -export function billingIdToPlan(billingId: string): Models.BillingPlan | null { +export function billingIdToPlan(billingId: string | null | undefined): Models.BillingPlan | null { + if (!billingId) { + return null; + } + const plansInfoStore = getPlansInfoStore(); if (plansInfoStore.has(billingId)) { return plansInfoStore.get(billingId); @@ -287,9 +291,9 @@ export const actionRequiredInvoices = writable(null); export const showUsageRatesModal = writable(false); export const useNewPricingModal = derived(currentPlan, ($plan) => $plan?.usagePerProject === true); -export function checkForUsageFees(plan: string, id: PlanServices) { +export function checkForUsageFees(plan: string | null | undefined, id: PlanServices) { const billingPlan = billingIdToPlan(plan); - const supportsUsage = Object.keys(billingPlan.usage).length > 0; + const supportsUsage = Object.keys(billingPlan?.usage ?? {}).length > 0; if (supportsUsage) { switch (id) { @@ -629,7 +633,7 @@ export async function checkForMissingPaymentMethod() { // Display upgrade banner for new users after 1 week for 30 days export async function checkForNewDevUpgradePro(org: Models.Organization) { // browser or plan check. - if (!browser || !org.billingPlanDetails.supportsCredits) return; + if (!browser || !org?.billingPlanDetails?.supportsCredits) return; // already dismissed by user! if (localStorage.getItem('newDevUpgradePro')) return; @@ -640,6 +644,8 @@ export async function checkForNewDevUpgradePro(org: Models.Organization) { const now = new Date().getTime(); const account = get(user); + if (!account?.$createdAt) return; + const accountCreated = new Date(account.$createdAt).getTime(); if (now - accountCreated < 1000 * 60 * 60 * 24 * 7) return; From b88f43b848eb8416f69052ec37497af33468d89f Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Wed, 20 May 2026 18:32:13 +0530 Subject: [PATCH 2/2] Guard project limitation plan lookup --- src/lib/stores/billing.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 1cb07e1417..e97ff4dde2 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -311,10 +311,10 @@ export function checkForUsageFees(plan: string | null | undefined, id: PlanServi } else return false; } -export function checkForProjectLimitation(plan: string, id: PlanServices) { +export function checkForProjectLimitation(plan: string | null | undefined, id: PlanServices) { if (id === 'members') { const billingPlan = billingIdToPlan(plan); - const hasUnlimitedProjects = billingPlan.projects === 0; + const hasUnlimitedProjects = billingPlan?.projects === 0; if (hasUnlimitedProjects) { return false; // No project limitation for members on Pro/Scale plans