From 3f073556e050f131cdfe1289e7f195fa8b30eaf9 Mon Sep 17 00:00:00 2001 From: Connor Yoh Date: Thu, 20 Nov 2025 11:12:57 +0000 Subject: [PATCH] LicenseContext only if admin --- .../proprietary/contexts/LicenseContext.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/frontend/src/proprietary/contexts/LicenseContext.tsx b/frontend/src/proprietary/contexts/LicenseContext.tsx index 9f40428d6..9414dcf5d 100644 --- a/frontend/src/proprietary/contexts/LicenseContext.tsx +++ b/frontend/src/proprietary/contexts/LicenseContext.tsx @@ -1,5 +1,6 @@ import React, { createContext, useContext, useState, useCallback, useEffect, ReactNode } from 'react'; import licenseService, { LicenseInfo } from '@app/services/licenseService'; +import { useAppConfig } from '@app/contexts/AppConfigContext'; interface LicenseContextValue { licenseInfo: LicenseInfo | null; @@ -15,11 +16,19 @@ interface LicenseProviderProps { } export const LicenseProvider: React.FC = ({ children }) => { + const { config } = useAppConfig(); const [licenseInfo, setLicenseInfo] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const refetchLicense = useCallback(async () => { + // Only fetch license info if user is an admin + if (!config?.isAdmin) { + console.debug('[LicenseContext] User is not an admin, skipping license fetch'); + setLoading(false); + return; + } + try { setLoading(true); setError(null); @@ -33,12 +42,14 @@ export const LicenseProvider: React.FC = ({ children }) => } finally { setLoading(false); } - }, []); + }, [config?.isAdmin]); - // Fetch license info on mount + // Fetch license info when config changes (only if user is admin) useEffect(() => { - refetchLicense(); - }, [refetchLicense]); + if (config) { + refetchLicense(); + } + }, [config, refetchLicense]); const contextValue: LicenseContextValue = { licenseInfo,