diff --git a/src/App.jsx b/src/App.jsx index a052515..ab671e5 100755 --- a/src/App.jsx +++ b/src/App.jsx @@ -110,22 +110,41 @@ function App() { const handleLogout = async () => { try { - await axios.post(`/api/auth/logout`, null, { - withCredentials: true, - }); + const token = localStorage.getItem('access_token'); + + if (!token) { + // Если нет токена - просто очищаем данные + cleanup(); + return; + } + + try { + await axios.post('/api/auth/logout', {}, { + headers: { + 'Authorization': `Bearer ${token}`, + 'Content-Type': 'application/json' + } + }); + } finally { + cleanup(); + } - localStorage.removeItem('access_token'); - localStorage.removeItem('user'); - setAuthState({ - isAuthenticated: false, - isLoading: false, - user: null, - }); - setShowLoginModal(true); } catch (error) { - console.error('Logout failed:', error); + console.error('Logout error:', error); + cleanup(); } }; + + function cleanup() { + localStorage.removeItem('access_token'); + localStorage.removeItem('user'); + setAuthState({ + isAuthenticated: false, + isLoading: false, + user: null, + }); + setShowLoginModal(true); + } // Полноэкранный лоадер во время проверки авторизации if (authState.isLoading) { return ( diff --git a/src/main.jsx b/src/main.jsx index b9a1a6d..9f03db3 100755 --- a/src/main.jsx +++ b/src/main.jsx @@ -3,6 +3,7 @@ import { createRoot } from 'react-dom/client' import './index.css' import App from './App.jsx' + createRoot(document.getElementById('root')).render( diff --git a/vite.config.js b/vite.config.js index 88ecdbf..863fb27 100755 --- a/vite.config.js +++ b/vite.config.js @@ -14,8 +14,12 @@ export default defineConfig({ rewrite: (path) => path.replace(/^\/ai-api/, ''), }, '/api': { - target: 'http://192.168.2.39:3000', + target: 'http://localhost:3000', changeOrigin: true, + bypass(req, res, options) { + console.log('Proxying request:', req.url); + } + } } }