Skip to content

Commit

Permalink
Merge pull request #623 from ita-social-projects/#584-LogOut
Browse files Browse the repository at this point in the history
#584 log out
  • Loading branch information
ohorodnykostap authored Jun 10, 2024
2 parents 1045435 + 0952d80 commit 2936fdb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 40 deletions.
27 changes: 0 additions & 27 deletions FrontEnd/src/components/HeaderFooter/header/navbar/Logout.jsx

This file was deleted.

18 changes: 15 additions & 3 deletions FrontEnd/src/components/HeaderFooter/header/navbar/Profile.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link, useNavigate } from 'react-router-dom';

import axios from 'axios';
import { useAuth } from '../../../../hooks';

import DropdownMenu from './DropdownMenu';
Expand All @@ -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 (
<div className={css['header-profile-section']}>
<img
Expand All @@ -24,7 +36,7 @@ function Profile() {
/>
<DropdownMenu toggleText="Профіль">
<Link to="/profile/user-info">Профіль</Link>
<Link to="/logout">Вихід</Link>
<button onClick={performLogout}>Вихід</button>
</DropdownMenu>
</div>
);
Expand Down
6 changes: 0 additions & 6 deletions FrontEnd/src/components/basicPage/BasicPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -117,11 +116,6 @@ function BasicPage() {
) : (
<Route path="/login" element={<AuthorizationPage />} />
)}
{!isAuth ? (
<Route path="/logout" element={<Navigate to="/" />} />
) : (
<Route path="/logout" element={<Logout />} />
)}
{isAuth ? (
<Route
path="/sign-up"
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/src/components/profileList/ProfileListPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function ProfileListPage({ isAuthorized }) {
data: fetchedProfiles,
error,
isLoading,
} = useSWR(filterSaved ? urlForSaved : urlForAll, fetcher);
} = useSWR(filterSaved && isAuthorized ? urlForSaved : urlForAll, fetcher);

const handleRadioSelect = () => {
if (!filterSaved) {
Expand Down
3 changes: 0 additions & 3 deletions FrontEnd/src/context/AuthContextProvider.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -47,7 +45,6 @@ export function AuthProvider({ children }) {
setIsAuth(false);
setIsStaff(false);
setUser(null);
navigate('/', { replace: true });
};

useEffect(() => {
Expand Down

0 comments on commit 2936fdb

Please sign in to comment.