fixed a bug with logout

pull/56/head
SovietSpiderCat 2025-08-07 04:44:54 +03:00
parent 08fde58a30
commit be3bf3b21e
3 changed files with 37 additions and 13 deletions

View File

@ -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 (

View File

@ -3,6 +3,7 @@ import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />

View File

@ -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);
}
}
}
}