yangdx
commited on
Commit
·
0d8fa96
1
Parent(s):
1e26fbc
Add application state reset on login page mount
Browse files- Reset all application state on login page
- Clear authentication and session storage
- Reset graph, backend, and settings state
- Ensure clean environment for new session
- Centralized state reset in navigation service
lightrag_webui/src/features/LoginPage.tsx
CHANGED
@@ -4,6 +4,7 @@ import { useAuthStore } from '@/stores/state'
|
|
4 |
import { loginToServer, getAuthStatus } from '@/api/lightrag'
|
5 |
import { toast } from 'sonner'
|
6 |
import { useTranslation } from 'react-i18next'
|
|
|
7 |
|
8 |
import { Card, CardContent, CardHeader } from '@/components/ui/Card'
|
9 |
import Input from '@/components/ui/Input'
|
@@ -20,6 +21,11 @@ const LoginPage = () => {
|
|
20 |
const [password, setPassword] = useState('')
|
21 |
const [checkingAuth, setCheckingAuth] = useState(true)
|
22 |
|
|
|
|
|
|
|
|
|
|
|
23 |
// Check if authentication is configured
|
24 |
useEffect(() => {
|
25 |
let isMounted = true; // Flag to prevent state updates after unmount
|
|
|
4 |
import { loginToServer, getAuthStatus } from '@/api/lightrag'
|
5 |
import { toast } from 'sonner'
|
6 |
import { useTranslation } from 'react-i18next'
|
7 |
+
import { navigationService } from '@/services/navigation'
|
8 |
|
9 |
import { Card, CardContent, CardHeader } from '@/components/ui/Card'
|
10 |
import Input from '@/components/ui/Input'
|
|
|
21 |
const [password, setPassword] = useState('')
|
22 |
const [checkingAuth, setCheckingAuth] = useState(true)
|
23 |
|
24 |
+
// Reset application state on first mount
|
25 |
+
useEffect(() => {
|
26 |
+
navigationService.resetAllApplicationState();
|
27 |
+
}, []); // Empty dependency array means this runs only once on mount
|
28 |
+
|
29 |
// Check if authentication is configured
|
30 |
useEffect(() => {
|
31 |
let isMounted = true; // Flag to prevent state updates after unmount
|
lightrag_webui/src/services/navigation.ts
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
import { NavigateFunction } from 'react-router-dom';
|
|
|
|
|
|
|
2 |
|
3 |
class NavigationService {
|
4 |
private navigate: NavigateFunction | null = null;
|
@@ -7,7 +10,42 @@ class NavigationService {
|
|
7 |
this.navigate = navigate;
|
8 |
}
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
navigateToLogin() {
|
|
|
|
|
|
|
11 |
if (this.navigate) {
|
12 |
this.navigate('/login');
|
13 |
}
|
|
|
1 |
import { NavigateFunction } from 'react-router-dom';
|
2 |
+
import { useAuthStore, useBackendState } from '@/stores/state';
|
3 |
+
import { useGraphStore } from '@/stores/graph';
|
4 |
+
import { useSettingsStore } from '@/stores/settings';
|
5 |
|
6 |
class NavigationService {
|
7 |
private navigate: NavigateFunction | null = null;
|
|
|
10 |
this.navigate = navigate;
|
11 |
}
|
12 |
|
13 |
+
/**
|
14 |
+
* Reset all application state to ensure a clean environment.
|
15 |
+
* This function should be called when:
|
16 |
+
* 1. User logs out
|
17 |
+
* 2. Authentication token expires
|
18 |
+
* 3. Direct access to login page
|
19 |
+
*/
|
20 |
+
resetAllApplicationState() {
|
21 |
+
console.log('Resetting all application state...');
|
22 |
+
|
23 |
+
// Clear authentication state
|
24 |
+
localStorage.removeItem('LIGHTRAG-API-TOKEN');
|
25 |
+
sessionStorage.clear();
|
26 |
+
useAuthStore.getState().logout();
|
27 |
+
|
28 |
+
// Reset graph state
|
29 |
+
const graphStore = useGraphStore.getState();
|
30 |
+
graphStore.reset();
|
31 |
+
graphStore.setGraphDataFetchAttempted(false);
|
32 |
+
graphStore.setLabelsFetchAttempted(false);
|
33 |
+
|
34 |
+
// Reset backend state
|
35 |
+
useBackendState.getState().clear();
|
36 |
+
|
37 |
+
// Reset retrieval history while preserving other user preferences
|
38 |
+
useSettingsStore.getState().setRetrievalHistory([]);
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Navigate to login page after resetting application state
|
43 |
+
* to ensure a clean environment for the next session
|
44 |
+
*/
|
45 |
navigateToLogin() {
|
46 |
+
// Reset state before navigation
|
47 |
+
this.resetAllApplicationState();
|
48 |
+
|
49 |
if (this.navigate) {
|
50 |
this.navigate('/login');
|
51 |
}
|