From 1ebd16efe08e6ce70667df210f64dcdef29e4032 Mon Sep 17 00:00:00 2001 From: edwin6666 Date: Fri, 7 Jul 2023 11:15:29 -0400 Subject: [PATCH 1/2] Feat: logout option only if a user exists --- src/components/Navbar/Navbar.jsx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/Navbar/Navbar.jsx b/src/components/Navbar/Navbar.jsx index a4513fb..3fd1ef7 100644 --- a/src/components/Navbar/Navbar.jsx +++ b/src/components/Navbar/Navbar.jsx @@ -1,12 +1,14 @@ import React, { useState } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faSignOutAlt } from '@fortawesome/free-solid-svg-icons'; -import { Link } from 'react-router-dom'; +import { Link, useLocation } from 'react-router-dom'; const Navbar = () => { + const location = useLocation(); + const isLoginPage = location.pathname === '/login'; + const handleLogout = () => { - - window.location= "/login"; + window.location = "/login"; }; const [open, setOpen] = useState(true); @@ -58,11 +60,13 @@ const Navbar = () => { > Contact -
setOpen(false)}> - -
+ {!isLoginPage && ( +
setOpen(false)}> + +
+ )} From 89aeb1412abc472d8212737fede373ce8c34d0df Mon Sep 17 00:00:00 2001 From: edwin6666 Date: Sat, 8 Jul 2023 12:35:55 -0400 Subject: [PATCH 2/2] Feat: logout function --- src/components/Navbar/Navbar.jsx | 3 +++ src/components/PostCard.jsx | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/Navbar/Navbar.jsx b/src/components/Navbar/Navbar.jsx index 3fd1ef7..303d205 100644 --- a/src/components/Navbar/Navbar.jsx +++ b/src/components/Navbar/Navbar.jsx @@ -2,12 +2,15 @@ import React, { useState } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faSignOutAlt } from '@fortawesome/free-solid-svg-icons'; import { Link, useLocation } from 'react-router-dom'; +import useAuth from "../../hooks/useAuth"; const Navbar = () => { const location = useLocation(); const isLoginPage = location.pathname === '/login'; + const { setAuth } = useAuth(); const handleLogout = () => { + setAuth({ roles: null, token: null }); window.location = "/login"; }; diff --git a/src/components/PostCard.jsx b/src/components/PostCard.jsx index 477e245..ea6a7bb 100644 --- a/src/components/PostCard.jsx +++ b/src/components/PostCard.jsx @@ -89,13 +89,13 @@ export function PostCard({ post }) {
{" "} {" "}