fix(organizations): remove org calls when billing is disabled (#1211)

This commit is contained in:
Waleed
2025-09-01 09:48:58 -07:00
committed by GitHub
parent 43cb124d97
commit 9ccb7600f9

View File

@@ -2,6 +2,7 @@ import { create } from 'zustand'
import { devtools } from 'zustand/middleware'
import { client } from '@/lib/auth-client'
import { checkEnterprisePlan } from '@/lib/billing/subscriptions/utils'
import { getEnv, isTruthy } from '@/lib/env'
import { createLogger } from '@/lib/logs/console/logger'
import type {
OrganizationStore,
@@ -17,6 +18,8 @@ import {
const logger = createLogger('OrganizationStore')
const isBillingEnabled = isTruthy(getEnv('NEXT_PUBLIC_BILLING_ENABLED'))
const CACHE_DURATION = 30 * 1000
export const useOrganizationStore = create<OrganizationStore>()(
@@ -49,6 +52,20 @@ export const useOrganizationStore = create<OrganizationStore>()(
hasEnterprisePlan: false,
loadData: async () => {
if (!isBillingEnabled) {
logger.debug('Billing disabled, skipping organization data loading')
set({
organizations: [],
activeOrganization: null,
hasTeamPlan: false,
hasEnterprisePlan: false,
isLoading: false,
error: null,
lastFetched: Date.now(),
})
return
}
const state = get()
if (state.lastFetched && Date.now() - state.lastFetched < CACHE_DURATION) {
@@ -287,6 +304,11 @@ export const useOrganizationStore = create<OrganizationStore>()(
},
refreshOrganization: async () => {
if (!isBillingEnabled) {
logger.debug('Billing disabled, skipping organization refresh')
return
}
const { activeOrganization } = get()
if (!activeOrganization?.id) return
@@ -318,6 +340,15 @@ export const useOrganizationStore = create<OrganizationStore>()(
// Organization management
createOrganization: async (name: string, slug: string) => {
if (!isBillingEnabled) {
logger.debug('Billing disabled, skipping organization creation')
set({
error: 'Organizations are only available when billing is enabled',
isCreatingOrg: false,
})
return
}
set({ isCreatingOrg: true, error: null })
try {