@@ -2,6 +2,7 @@ import { create } from 'zustand'
22import { devtools } from 'zustand/middleware'
33import { client } from '@/lib/auth-client'
44import { checkEnterprisePlan } from '@/lib/billing/subscriptions/utils'
5+ import { getEnv , isTruthy } from '@/lib/env'
56import { createLogger } from '@/lib/logs/console/logger'
67import type {
78 OrganizationStore ,
@@ -17,6 +18,8 @@ import {
1718
1819const logger = createLogger ( 'OrganizationStore' )
1920
21+ const isBillingEnabled = isTruthy ( getEnv ( 'NEXT_PUBLIC_BILLING_ENABLED' ) )
22+
2023const CACHE_DURATION = 30 * 1000
2124
2225export const useOrganizationStore = create < OrganizationStore > ( ) (
@@ -49,6 +52,20 @@ export const useOrganizationStore = create<OrganizationStore>()(
4952 hasEnterprisePlan : false ,
5053
5154 loadData : async ( ) => {
55+ if ( ! isBillingEnabled ) {
56+ logger . debug ( 'Billing disabled, skipping organization data loading' )
57+ set ( {
58+ organizations : [ ] ,
59+ activeOrganization : null ,
60+ hasTeamPlan : false ,
61+ hasEnterprisePlan : false ,
62+ isLoading : false ,
63+ error : null ,
64+ lastFetched : Date . now ( ) ,
65+ } )
66+ return
67+ }
68+
5269 const state = get ( )
5370
5471 if ( state . lastFetched && Date . now ( ) - state . lastFetched < CACHE_DURATION ) {
@@ -287,6 +304,11 @@ export const useOrganizationStore = create<OrganizationStore>()(
287304 } ,
288305
289306 refreshOrganization : async ( ) => {
307+ if ( ! isBillingEnabled ) {
308+ logger . debug ( 'Billing disabled, skipping organization refresh' )
309+ return
310+ }
311+
290312 const { activeOrganization } = get ( )
291313 if ( ! activeOrganization ?. id ) return
292314
@@ -318,6 +340,15 @@ export const useOrganizationStore = create<OrganizationStore>()(
318340
319341 // Organization management
320342 createOrganization : async ( name : string , slug : string ) => {
343+ if ( ! isBillingEnabled ) {
344+ logger . debug ( 'Billing disabled, skipping organization creation' )
345+ set ( {
346+ error : 'Organizations are only available when billing is enabled' ,
347+ isCreatingOrg : false ,
348+ } )
349+ return
350+ }
351+
321352 set ( { isCreatingOrg : true , error : null } )
322353
323354 try {
0 commit comments