-
Notifications
You must be signed in to change notification settings - Fork 67
Logout button #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Logout button #142
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements dynamic login/logout functionality in the navbar and adds responsive layout improvements to the landing page. The navbar now shows "Logout" when a user is authenticated and "Login" when not, with proper token cleanup on logout.
- Added dynamic navbar authentication state with localStorage token checking
- Implemented logout functionality that clears user data and redirects to login
- Added redirect logic to prevent authenticated users from accessing the home page
- Updated landing page layout for better responsive design
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| client/src/components/common/Navbar.jsx | Implements dynamic login/logout button and authentication state management |
| client/src/pages/HomePage.jsx | Adds redirect logic for authenticated users |
| client/src/pages/LandingPage.jsx | Updates responsive layout and styling improvements |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| useEffect(() => { | ||
| const token = localStorage.getItem("token"); | ||
| if (token) { | ||
| navigate("/landing", { replace: true }); | ||
| } | ||
| }, [navigate]); |
Copilot
AI
Oct 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The useEffect hook lacks proper indentation. It should be aligned with other top-level code in the component.
| useEffect(() => { | |
| const token = localStorage.getItem("token"); | |
| if (token) { | |
| navigate("/landing", { replace: true }); | |
| } | |
| }, [navigate]); | |
| useEffect(() => { | |
| const token = localStorage.getItem("token"); | |
| if (token) { | |
| navigate("/landing", { replace: true }); | |
| } | |
| }, [navigate]); |
| const token = localStorage.getItem("token"); | ||
| setIsLoggedIn(!!token); |
Copilot
AI
Oct 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The useEffect should listen for changes to localStorage to handle cases where the token might be modified outside this component. Consider adding a storage event listener or using a context/state management solution for authentication state.
| const token = localStorage.getItem("token"); | |
| setIsLoggedIn(!!token); | |
| const checkToken = () => { | |
| const token = localStorage.getItem("token"); | |
| setIsLoggedIn(!!token); | |
| }; | |
| checkToken(); | |
| const handleStorage = (event) => { | |
| if (event.key === "token") { | |
| checkToken(); | |
| } | |
| }; | |
| window.addEventListener("storage", handleStorage); | |
| return () => { | |
| window.removeEventListener("storage", handleStorage); | |
| }; |
|
Fix: #72 also |
Fix: #85
Screeshot:
