Добавил кривой LogOut
This commit is contained in:
parent
149b0619e0
commit
5b42813934
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
go-auth/__debug_bin4224424542.exe
|
@ -3,6 +3,7 @@ import Authorization from './component/page/Authorization';
|
|||||||
import Registration from './component/page/Registration';
|
import Registration from './component/page/Registration';
|
||||||
import Main from './component/page/Main';
|
import Main from './component/page/Main';
|
||||||
import Profile from './component/profile/Profile';
|
import Profile from './component/profile/Profile';
|
||||||
|
import Logout from './component/page/Logout';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
@ -12,6 +13,7 @@ function App() {
|
|||||||
<Route path="/login" element={<Authorization />} />
|
<Route path="/login" element={<Authorization />} />
|
||||||
<Route path="/register" element={<Registration />} />
|
<Route path="/register" element={<Registration />} />
|
||||||
<Route path="/profile" element={<Profile />} />
|
<Route path="/profile" element={<Profile />} />
|
||||||
|
<Route path="/logout" element={<Logout />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
|
29
react-auth/src/component/page/Logout.jsx
Normal file
29
react-auth/src/component/page/Logout.jsx
Normal 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;
|
@ -3,6 +3,8 @@ import axios from "axios";
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { Card, Spin, Alert, Button } from "antd";
|
import { Card, Spin, Alert, Button } from "antd";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const Profile = () => {
|
const Profile = () => {
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user