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 (