Добавил кривой LogOut

This commit is contained in:
maksim 2025-03-09 12:41:55 +04:00
parent 149b0619e0
commit 5b42813934
4 changed files with 34 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
go-auth/__debug_bin4224424542.exe

View File

@ -3,6 +3,7 @@ import Authorization from './component/page/Authorization';
import Registration from './component/page/Registration';
import Main from './component/page/Main';
import Profile from './component/profile/Profile';
import Logout from './component/page/Logout';
function App() {
return (
@ -12,6 +13,7 @@ function App() {
<Route path="/login" element={<Authorization />} />
<Route path="/register" element={<Registration />} />
<Route path="/profile" element={<Profile />} />
<Route path="/logout" element={<Logout />} />
</Routes>
</Router>
);

View File

@ -0,0 +1,29 @@
import React, { useState } from "react";
import { Button } from "antd";
import { useNavigate } from "react-router-dom";
import axios from "axios";
const Logout = () => {
const navigate = useNavigate();
const handleLogout = async () => {
try {
// Отправляем запрос на сервер для логаута
await axios.post("http://localhost:8000/api/logout", {}, { withCredentials: true });
// Перенаправляем пользователя на страницу входа
navigate("/login");
} catch (error) {
console.error("Ошибка логаута:", error);
}
};
return (
<div className="flex justify-center items-center min-h-screen bg-gray-100">
<Button type="primary" onClick={handleLogout}>
Выйти
</Button>
</div>
);
};
export default Logout;

View File

@ -3,6 +3,8 @@ import axios from "axios";
import { useNavigate } from "react-router-dom";
import { Card, Spin, Alert, Button } from "antd";
const Profile = () => {
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);