From cc2d6047820e891c32b8cab18b89e10794072870 Mon Sep 17 00:00:00 2001 From: yangdx Date: Sat, 5 Apr 2025 12:05:37 +0800 Subject: [PATCH] Keep graph query label after 401 error for post-login data reload --- lightrag_webui/src/hooks/useLightragGraph.tsx | 18 +++++++++++++----- lightrag_webui/src/services/navigation.ts | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lightrag_webui/src/hooks/useLightragGraph.tsx b/lightrag_webui/src/hooks/useLightragGraph.tsx index eadd67fb..bb1b0a4e 100644 --- a/lightrag_webui/src/hooks/useLightragGraph.tsx +++ b/lightrag_webui/src/hooks/useLightragGraph.tsx @@ -342,15 +342,23 @@ const useLightrangeGraph = () => { // Still mark graph as empty for other logic state.setGraphIsEmpty(true); - // Only clear current label if it's not already empty - if (currentQueryLabel) { + // Check if the empty graph is due to 401 authentication error + const errorMessage = useBackendState.getState().message; + const isAuthError = errorMessage && errorMessage.includes('Authentication required'); + + // Only clear queryLabel if it's not an auth error and current label is not empty + if (!isAuthError && currentQueryLabel) { useSettingsStore.getState().setQueryLabel(''); } - // Clear last successful query label to ensure labels are fetched next time - state.setLastSuccessfulQueryLabel(''); + // Only clear last successful query label if it's not an auth error + if (!isAuthError) { + state.setLastSuccessfulQueryLabel(''); + } else { + console.log('Keep queryLabel for post-login reload'); + } - console.log('Graph data is empty, created graph with empty graph node'); + console.log(`Graph data is empty, created graph with empty graph node. Auth error: ${isAuthError}`); } else { // Create and set new graph const newSigmaGraph = createSigmaGraph(data); diff --git a/lightrag_webui/src/services/navigation.ts b/lightrag_webui/src/services/navigation.ts index 19da250e..97eb5b55 100644 --- a/lightrag_webui/src/services/navigation.ts +++ b/lightrag_webui/src/services/navigation.ts @@ -32,7 +32,7 @@ class NavigationService { // Reset backend state useBackendState.getState().clear(); - // Reset retrieval history while preserving other user preferences + // Reset retrieval history message while preserving other user preferences useSettingsStore.getState().setRetrievalHistory([]); // Clear authentication state