Skip to content

Commit

Permalink
Merge pull request #811 from MohammedJunaid02/MohammedJunaid02/fixFor…
Browse files Browse the repository at this point in the history
…Logout

Fixed Issue Number - 708 Fixed :- Added conditional logic to render Sign Out button for Logged In Users only
  • Loading branch information
SUGAM-ARORA authored Oct 16, 2024
2 parents 5d7c308 + 3e3a96a commit 2b2889c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Components/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function Menu() {
const [sidebarOpen, setSidebarOpen] = useState(false);
const [isMobile, setIsMobile] = useState(window.innerWidth < 524);
const [showStopwatch, setShowStopwatch] = useState(false); // State to handle stopwatch visibility
const [isUserLoggedIn, setIsUserLoggedIn] = useState(localStorage.getItem('user') ? true : false);

useEffect(() => {
const handleResize = () => {
Expand All @@ -30,10 +31,12 @@ function Menu() {

window.addEventListener("resize", handleResize);

const user = localStorage.getItem('user');
setIsUserLoggedIn(user ? true : false);
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);
}, [isUserLoggedIn]);

const toggleSidebar = () => {
setSidebarOpen(!sidebarOpen);
Expand All @@ -44,10 +47,8 @@ function Menu() {
};

const handleSignOut = () => {
console.log("User signed out");
setTimeout(() => {
// Handle any additional sign-out logic here
}, 3000);
localStorage.removeItem('user');
setIsUserLoggedIn(false);
};

const { theme } = useContext(ThemeContext)
Expand Down Expand Up @@ -122,12 +123,14 @@ function Menu() {
<span className="tooltip" style={{ marginLeft: '10px', fontSize: '1.1rem', color: 'white' }}>Settings</span>
</Link>
</li>
<li style={{ padding: '1rem', display: 'flex', alignItems: 'center', gap: '10px' }}>
{isUserLoggedIn && (
<li style={{ padding: '1rem', display: 'flex', alignItems: 'center', gap: '10px' }}>
<Link to="/" style={{ color: 'white', textDecoration: 'none', display: 'flex', alignItems: 'center' }}>
<FaSignOutAlt size={30} />
<span className="tooltip" style={{ marginLeft: '10px', fontSize: '1.1rem', color: 'white' }}>Sign Out</span>
<span className="tooltip" style={{ marginLeft: '10px', fontSize: '1.1rem', color: 'white' }} onClick={handleSignOut}>SignOut</span>
</Link>
</li>
)}
</ul>
</div>

Expand Down

0 comments on commit 2b2889c

Please sign in to comment.