diff --git a/lightrag_webui/src/AppRouter.tsx b/lightrag_webui/src/AppRouter.tsx index e85a97be..f6d1d08b 100644 --- a/lightrag_webui/src/AppRouter.tsx +++ b/lightrag_webui/src/AppRouter.tsx @@ -43,7 +43,7 @@ const ProtectedRoute = ({ children }: ProtectedRouteProps) => { if (!status.auth_configured && status.access_token) { // If auth is not configured, use the guest token - useAuthStore.getState().login(status.access_token, true) + useAuthStore.getState().login(status.access_token, true, status.core_version, status.api_version) if (status.message) { toast.info(status.message) } @@ -126,7 +126,7 @@ const AppContent = () => { if (!status.auth_configured && status.access_token) { // If auth is not configured, use the guest token - useAuthStore.getState().login(status.access_token, true) + useAuthStore.getState().login(status.access_token, true, status.core_version, status.api_version) if (status.message) { toast.info(status.message) } diff --git a/lightrag_webui/src/stores/state.ts b/lightrag_webui/src/stores/state.ts index f4f19cb3..17ab0b13 100644 --- a/lightrag_webui/src/stores/state.ts +++ b/lightrag_webui/src/stores/state.ts @@ -88,20 +88,23 @@ const isGuestToken = (token: string): boolean => { // Initialize auth state from localStorage const initAuthState = (): { isAuthenticated: boolean; isGuestMode: boolean; coreVersion: string | null; apiVersion: string | null } => { const token = localStorage.getItem('LIGHTRAG-API-TOKEN'); + const coreVersion = localStorage.getItem('LIGHTRAG-CORE-VERSION'); + const apiVersion = localStorage.getItem('LIGHTRAG-API-VERSION'); + if (!token) { return { isAuthenticated: false, isGuestMode: false, - coreVersion: null, - apiVersion: null + coreVersion: coreVersion, + apiVersion: apiVersion }; } return { isAuthenticated: true, isGuestMode: isGuestToken(token), - coreVersion: localStorage.getItem('LIGHTRAG-CORE-VERSION'), - apiVersion: localStorage.getItem('LIGHTRAG-API-VERSION') + coreVersion: coreVersion, + apiVersion: apiVersion }; }; @@ -118,7 +121,6 @@ export const useAuthStore = create(set => { login: (token, isGuest = false, coreVersion = null, apiVersion = null) => { localStorage.setItem('LIGHTRAG-API-TOKEN', token); - // 存储版本信息到 localStorage if (coreVersion) { localStorage.setItem('LIGHTRAG-CORE-VERSION', coreVersion); } @@ -129,19 +131,22 @@ export const useAuthStore = create(set => { set({ isAuthenticated: true, isGuestMode: isGuest, - coreVersion, - apiVersion + coreVersion: coreVersion, + apiVersion: apiVersion }); }, logout: () => { localStorage.removeItem('LIGHTRAG-API-TOKEN'); + + const coreVersion = localStorage.getItem('LIGHTRAG-CORE-VERSION'); + const apiVersion = localStorage.getItem('LIGHTRAG-API-VERSION'); set({ isAuthenticated: false, isGuestMode: false, - coreVersion: null, - apiVersion: null + coreVersion: coreVersion, + apiVersion: apiVersion }); } };