Refactor navigation and authentication flow, prevent mounting login page multiple times

- Improved protected route handling
- Enhanced direct login access detection
- Centralized navigation logic
- Optimized state reset process
- Fixed logout navigation behavior
This commit is contained in:
yangdx
2025-03-19 12:45:08 +08:00
parent bc4c16b06a
commit 50a8b5fb6d
8 changed files with 120 additions and 94 deletions

View File

@@ -4,8 +4,6 @@ import { useAuthStore } from '@/stores/state'
import { loginToServer, getAuthStatus } from '@/api/lightrag'
import { toast } from 'sonner'
import { useTranslation } from 'react-i18next'
import { navigationService } from '@/services/navigation'
import { Card, CardContent, CardHeader } from '@/components/ui/Card'
import Input from '@/components/ui/Input'
import Button from '@/components/ui/Button'
@@ -21,12 +19,11 @@ const LoginPage = () => {
const [password, setPassword] = useState('')
const [checkingAuth, setCheckingAuth] = useState(true)
// Reset application state on first mount
useEffect(() => {
navigationService.resetAllApplicationState();
}, []); // Empty dependency array means this runs only once on mount
console.log('LoginPage mounted')
}, []);
// Check if authentication is configured
// Check if authentication is configured, skip login if not
useEffect(() => {
let isMounted = true; // Flag to prevent state updates after unmount