From a9c02364773dc41aeb4ea7bdad11b93d8fa4d213 Mon Sep 17 00:00:00 2001 From: Dario Ghunney Ware Date: Tue, 28 Oct 2025 16:32:17 +0000 Subject: [PATCH] fixing duplicate calls --- .../src/main/resources/application.properties | 4 +-- .../filter/JwtAuthenticationFilter.java | 1 - .../src/core/contexts/AppConfigContext.tsx | 30 ++++++++++++++----- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/core/src/main/resources/application.properties b/app/core/src/main/resources/application.properties index 1756c911d..18e1f4f8a 100644 --- a/app/core/src/main/resources/application.properties +++ b/app/core/src/main/resources/application.properties @@ -3,9 +3,9 @@ logging.level.org.springframework=WARN logging.level.org.hibernate=WARN logging.level.org.eclipse.jetty=WARN #logging.level.org.springframework.security.oauth2=DEBUG -logging.level.org.springframework.security=DEBUG +#logging.level.org.springframework.security=DEBUG #logging.level.org.opensaml=DEBUG -logging.level.stirling.software.proprietary.security=DEBUG +#logging.level.stirling.software.proprietary.security=DEBUG logging.level.com.zaxxer.hikari=WARN spring.jpa.open-in-view=false server.forward-headers-strategy=NATIVE diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/security/filter/JwtAuthenticationFilter.java b/app/proprietary/src/main/java/stirling/software/proprietary/security/filter/JwtAuthenticationFilter.java index 032932f92..5ec762fd8 100644 --- a/app/proprietary/src/main/java/stirling/software/proprietary/security/filter/JwtAuthenticationFilter.java +++ b/app/proprietary/src/main/java/stirling/software/proprietary/security/filter/JwtAuthenticationFilter.java @@ -80,7 +80,6 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { String requestURI = request.getRequestURI(); String contextPath = request.getContextPath(); - if (!isPublicAuthEndpoint(requestURI, contextPath)) { // For API requests, return 401 JSON String acceptHeader = request.getHeader("Accept"); diff --git a/frontend/src/core/contexts/AppConfigContext.tsx b/frontend/src/core/contexts/AppConfigContext.tsx index da2e5d2e6..d59fa63ed 100644 --- a/frontend/src/core/contexts/AppConfigContext.tsx +++ b/frontend/src/core/contexts/AppConfigContext.tsx @@ -1,4 +1,4 @@ -import React, { createContext, useContext, useState, useEffect } from 'react'; +import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react'; import { useRequestHeaders } from '@app/hooks/useRequestHeaders'; // Helper to get JWT from localStorage for Authorization header @@ -43,8 +43,12 @@ interface AppConfigContextValue { } // Create context -const AppConfigContext = createContext(undefined); - +const AppConfigContext = createContext({ + config: null, + loading: true, + error: null, + refetch: async () => {}, +}); /** * Provider component that fetches and provides app configuration * Should be placed at the top level of the app, before any components that need config @@ -59,10 +63,21 @@ export const AppConfigProvider: React.FC<{ children: React.ReactNode }> = ({ chi const fetchConfig = async () => { // Prevent duplicate fetches if (hasFetched) { - console.debug('[useAppConfig] Already fetched, skipping'); + console.debug('[AppConfig] Already fetched, skipping'); return; } + // Don't fetch config if we're on the login page and don't have JWT + const isLoginPage = window.location.pathname.includes('/login'); + const hasJwt = !!localStorage.getItem('stirling_jwt'); + + if (isLoginPage && !hasJwt) { + console.debug('[AppConfigContext] On login page without JWT - using default config'); + setConfig({ enableLogin: true }); + setLoading(false); + return; + } + try { setLoading(true); setError(null); @@ -75,7 +90,7 @@ export const AppConfigProvider: React.FC<{ children: React.ReactNode }> = ({ chi if (!response.ok) { // On 401 (not authenticated), use default config with login enabled if (response.status === 401) { - console.debug('[useAppConfig] 401 error - using default config (login enabled)'); + console.debug('[AppConfig] 401 error - using default config (login enabled)'); setConfig({ enableLogin: true }); setLoading(false); return; @@ -84,7 +99,7 @@ export const AppConfigProvider: React.FC<{ children: React.ReactNode }> = ({ chi } const data: AppConfig = await response.json(); - console.debug('[AppConfig] Config fetched successfully:', data); + console.debug('[AppConfigContext] Config fetched successfully:', data); setConfig(data); } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred'; @@ -109,7 +124,7 @@ export const AppConfigProvider: React.FC<{ children: React.ReactNode }> = ({ chi // Listen for JWT availability (triggered on login/signup) useEffect(() => { const handleJwtAvailable = () => { - console.debug('[useAppConfig] JWT available event - refetching config'); + console.debug('[AppConfig] JWT available event - refetching config'); // Reset the flag to allow refetch with JWT setHasFetched(false); fetchConfig(); @@ -146,4 +161,3 @@ export function useAppConfig(): AppConfigContextValue { return context; } -