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

@@ -2,7 +2,6 @@ import axios, { AxiosError } from 'axios'
import { backendBaseUrl } from '@/lib/constants'
import { errorMessage } from '@/lib/utils'
import { useSettingsStore } from '@/stores/settings'
import { useAuthStore } from '@/stores/state'
import { navigationService } from '@/services/navigation'
// Types
@@ -174,10 +173,6 @@ axiosInstance.interceptors.response.use(
(error: AxiosError) => {
if (error.response) {
if (error.response?.status === 401) {
localStorage.removeItem('LIGHTRAG-API-TOKEN');
sessionStorage.clear();
useAuthStore.getState().logout();
// Use navigation service to handle redirection
navigationService.navigateToLogin();