diff --git a/FrontEnd/src/components/HeaderFooter/header/navbar/Logout.jsx b/FrontEnd/src/components/HeaderFooter/header/navbar/Logout.jsx deleted file mode 100644 index 17460efde..000000000 --- a/FrontEnd/src/components/HeaderFooter/header/navbar/Logout.jsx +++ /dev/null @@ -1,27 +0,0 @@ -import axios from 'axios'; -import { useNavigate } from 'react-router-dom'; -import { useEffect } from 'react'; -import { useAuth } from '../../../../hooks'; - -function Logout() { - const { isAuth, logout } = useAuth(); - const navigate = useNavigate(); - - useEffect(() => { - const performLogout = async () => { - if (isAuth) { - try { - await axios.post(`${process.env.REACT_APP_BASE_API_URL}/api/auth/token/logout`); - await logout(); - } catch (error) { - console.error('Error during logout', error); - } - } - navigate('/'); - }; - - performLogout(); - }, [isAuth, navigate]); -} - -export default Logout; diff --git a/FrontEnd/src/components/HeaderFooter/header/navbar/Profile.jsx b/FrontEnd/src/components/HeaderFooter/header/navbar/Profile.jsx index 67518fd4e..03342cd40 100644 --- a/FrontEnd/src/components/HeaderFooter/header/navbar/Profile.jsx +++ b/FrontEnd/src/components/HeaderFooter/header/navbar/Profile.jsx @@ -1,5 +1,5 @@ import { Link, useNavigate } from 'react-router-dom'; - +import axios from 'axios'; import { useAuth } from '../../../../hooks'; import DropdownMenu from './DropdownMenu'; @@ -8,12 +8,24 @@ import avatar_image from './Avatar.png'; function Profile() { - const { user } = useAuth(); + const { user, isAuth, logout } = useAuth(); const navigate = useNavigate(); + const navigateToProfile = () => { navigate(`/profile-detail/${user.profile_id}`); }; + const performLogout = async () => { + if (isAuth) { + try { + await axios.post(`${process.env.REACT_APP_BASE_API_URL}/api/auth/token/logout`); + await logout(); + } catch (error) { + console.error('Error during logout', error); + } + } + }; + return (
Профіль - Вихід +
); diff --git a/FrontEnd/src/components/basicPage/BasicPage.jsx b/FrontEnd/src/components/basicPage/BasicPage.jsx index d2ea74787..9d23dceed 100644 --- a/FrontEnd/src/components/basicPage/BasicPage.jsx +++ b/FrontEnd/src/components/basicPage/BasicPage.jsx @@ -9,7 +9,6 @@ import AuthorizationPage from '../authorization/AuthorizationPage'; import CookiesPolicyComponent from '../CookiesPolicyPage/CookiesPolicyComponent'; import Footer from '../HeaderFooter/footer/Footer'; import Header from '../HeaderFooter/header/Header'; -import Logout from '../HeaderFooter/header/navbar/Logout'; import Loader from '../loader/Loader'; import MainPage from '../landing-page/MainPage'; import PrivacyPolicy from '../PrivacyPolicyPage/PrivacyPolicyPage'; @@ -117,11 +116,6 @@ function BasicPage() { ) : ( } /> )} - {!isAuth ? ( - } /> - ) : ( - } /> - )} {isAuth ? ( { if (!filterSaved) { diff --git a/FrontEnd/src/context/AuthContextProvider.js b/FrontEnd/src/context/AuthContextProvider.js index 7e3549614..052c277aa 100644 --- a/FrontEnd/src/context/AuthContextProvider.js +++ b/FrontEnd/src/context/AuthContextProvider.js @@ -1,5 +1,4 @@ import { useEffect, useState } from 'react'; -import { useNavigate } from 'react-router-dom'; import useSWR from 'swr'; import axios from 'axios'; import { AuthContext } from '../context'; @@ -9,7 +8,6 @@ export function AuthProvider({ children }) { const [user, setUser] = useState(null); const [isLoading, setLoading] = useState(true); const [authToken, setAuthToken] = useState(localStorage.getItem('Token')); - const navigate = useNavigate(); const [isStaff, setIsStaff] = useState(false); const { data, error, mutate } = useSWR( authToken @@ -47,7 +45,6 @@ export function AuthProvider({ children }) { setIsAuth(false); setIsStaff(false); setUser(null); - navigate('/', { replace: true }); }; useEffect(() => {