mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-12-18 20:04:17 +01:00
fixing duplicate calls
This commit is contained in:
parent
e141f46832
commit
a9c0236477
@ -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
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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<AppConfigContextValue | undefined>(undefined);
|
||||
|
||||
const AppConfigContext = createContext<AppConfigContextValue | undefined>({
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user