Merge branch 'loginPage' into webui-node-expansion

This commit is contained in:
yangdx
2025-03-18 00:39:48 +08:00
24 changed files with 571 additions and 194 deletions

View File

@@ -7,6 +7,7 @@ import { Message, QueryRequest } from '@/api/lightrag'
type Theme = 'dark' | 'light' | 'system'
type Language = 'en' | 'zh'
type Tab = 'documents' | 'knowledge-graph' | 'retrieval' | 'api'
type Language = 'en' | 'zh'
interface SettingsState {
// Graph viewer settings

View File

@@ -16,6 +16,14 @@ interface BackendState {
setErrorMessage: (message: string, messageTitle: string) => void
}
interface AuthState {
isAuthenticated: boolean;
showLoginModal: boolean;
login: (token: string) => void;
logout: () => void;
setShowLoginModal: (show: boolean) => void;
}
const useBackendStateStoreBase = create<BackendState>()((set) => ({
health: true,
message: null,
@@ -57,3 +65,17 @@ const useBackendStateStoreBase = create<BackendState>()((set) => ({
const useBackendState = createSelectors(useBackendStateStoreBase)
export { useBackendState }
export const useAuthStore = create<AuthState>(set => ({
isAuthenticated: !!localStorage.getItem('LIGHTRAG-API-TOKEN'),
showLoginModal: false,
login: (token) => {
localStorage.setItem('LIGHTRAG-API-TOKEN', token);
set({ isAuthenticated: true, showLoginModal: false });
},
logout: () => {
localStorage.removeItem('LIGHTRAG-API-TOKEN');
set({ isAuthenticated: false });
},
setShowLoginModal: (show) => set({ showLoginModal: show })
}));