fixed a bug with logout
parent
08fde58a30
commit
be3bf3b21e
43
src/App.jsx
43
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 (
|
||||
|
|
|
|||
|
|
@ -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 />
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue