From 19f40d053ac81836f8f2fc4f74b3c7ad9de71928 Mon Sep 17 00:00:00 2001 From: Dario Ghunney Ware Date: Thu, 30 Oct 2025 10:42:24 +0000 Subject: [PATCH] resolving conflicts, testing everything still works --- .../configuration/SecurityConfiguration.java | 3 +-- .../src/core/contexts/AppConfigContext.tsx | 24 +++++++------------ frontend/src/core/hooks/useEndpointConfig.ts | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/security/configuration/SecurityConfiguration.java b/app/proprietary/src/main/java/stirling/software/proprietary/security/configuration/SecurityConfiguration.java index 756030b8a..49f98570a 100644 --- a/app/proprietary/src/main/java/stirling/software/proprietary/security/configuration/SecurityConfiguration.java +++ b/app/proprietary/src/main/java/stirling/software/proprietary/security/configuration/SecurityConfiguration.java @@ -146,8 +146,7 @@ public class SecurityConfiguration { cfg.setAllowedOriginPatterns( List.of( "http://localhost:*", // Still allow localhost for local deployments - "https://localhost:*" - )); + "https://localhost:*")); log.info("CORS configured for production mode"); } diff --git a/frontend/src/core/contexts/AppConfigContext.tsx b/frontend/src/core/contexts/AppConfigContext.tsx index 969557845..6890c2e12 100644 --- a/frontend/src/core/contexts/AppConfigContext.tsx +++ b/frontend/src/core/contexts/AppConfigContext.tsx @@ -1,5 +1,4 @@ import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react'; -import { useRequestHeaders } from '@app/hooks/useRequestHeaders'; // Helper to get JWT from localStorage for Authorization header function getAuthHeaders(): HeadersInit { @@ -53,16 +52,15 @@ const AppConfigContext = createContext({ * Provider component that fetches and provides app configuration * Should be placed at the top level of the app, before any components that need config */ -export const AppConfigProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { +export const AppConfigProvider: React.FC<{ children: ReactNode }> = ({ children }) => { const [config, setConfig] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); - const headers = useRequestHeaders(); - const [hasFetched, setHasFetched] = useState(false); + const [fetchCount, setFetchCount] = useState(0); - const fetchConfig = async () => { - // Prevent duplicate fetches - if (hasFetched) { + const fetchConfig = async (force = false) => { + // Prevent duplicate fetches unless forced + if (!force && fetchCount > 0) { console.debug('[AppConfig] Already fetched, skipping'); return; } @@ -81,7 +79,6 @@ export const AppConfigProvider: React.FC<{ children: React.ReactNode }> = ({ chi try { setLoading(true); setError(null); - setHasFetched(true); const response = await fetch('/api/v1/config/app-config', { headers: getAuthHeaders(), @@ -101,6 +98,7 @@ export const AppConfigProvider: React.FC<{ children: React.ReactNode }> = ({ chi const data: AppConfig = await response.json(); console.debug('[AppConfig] Config fetched successfully:', data); setConfig(data); + setFetchCount(prev => prev + 1); } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred'; setError(errorMessage); @@ -113,9 +111,6 @@ export const AppConfigProvider: React.FC<{ children: React.ReactNode }> = ({ chi }; useEffect(() => { - // Only fetch config if we have JWT or if checking for anonymous mode - const hasJwt = !!localStorage.getItem('stirling_jwt'); - // Always try to fetch config to check if login is disabled // The endpoint should be public and return proper JSON fetchConfig(); @@ -125,9 +120,8 @@ export const AppConfigProvider: React.FC<{ children: React.ReactNode }> = ({ chi useEffect(() => { const handleJwtAvailable = () => { console.debug('[AppConfig] JWT available event - refetching config'); - // Reset the flag to allow refetch with JWT - setHasFetched(false); - fetchConfig(); + // Force refetch with JWT + fetchConfig(true); }; window.addEventListener('jwt-available', handleJwtAvailable); @@ -138,7 +132,7 @@ export const AppConfigProvider: React.FC<{ children: React.ReactNode }> = ({ chi config, loading, error, - refetch: fetchConfig, + refetch: () => fetchConfig(true), }; return ( diff --git a/frontend/src/core/hooks/useEndpointConfig.ts b/frontend/src/core/hooks/useEndpointConfig.ts index 2edf45f32..1ce18e297 100644 --- a/frontend/src/core/hooks/useEndpointConfig.ts +++ b/frontend/src/core/hooks/useEndpointConfig.ts @@ -76,7 +76,7 @@ export function useMultipleEndpointsEnabled(endpoints: string[]): { const [endpointStatus, setEndpointStatus] = useState>({}); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); - const [_lastFetchedEndpoints, setLastFetchedEndpoints] = useState(''); + const [lastFetchedEndpoints, setLastFetchedEndpoints] = useState(''); const _headers = useRequestHeaders(); const fetchAllEndpointStatuses = async () => {