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:
@@ -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
|
||||
|
||||
|
@@ -6,8 +6,7 @@ import { useSettingsStore } from '@/stores/settings'
|
||||
import { useAuthStore } from '@/stores/state'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
|
||||
import { navigationService } from '@/services/navigation'
|
||||
import { ZapIcon, GithubIcon, LogOutIcon } from 'lucide-react'
|
||||
|
||||
interface NavigationTabProps {
|
||||
@@ -56,12 +55,10 @@ function TabsNavigation() {
|
||||
|
||||
export default function SiteHeader() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const { logout, isGuestMode } = useAuthStore()
|
||||
const { isGuestMode } = useAuthStore()
|
||||
|
||||
const handleLogout = () => {
|
||||
logout()
|
||||
navigate('/login')
|
||||
navigationService.navigateToLogin();
|
||||
}
|
||||
|
||||
return (
|
||||
|
Reference in New Issue
Block a user