Skip to content

Commit

Permalink
chore: fixed unnecessary log in option after getting logged in using …
Browse files Browse the repository at this point in the history
…jwt token
  • Loading branch information
Amnyadav committed Oct 11, 2024
1 parent 045630a commit b40129b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions frontend/src/components/Pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const Login = () => {
throw new Error(result.message || 'Login failed');
}
// Handle successful login (e.g., store token, redirect)
const token=result.token;
localStorage.setItem("token",JSON.stringify(token));
message.success('Login successful');
navigate('/');
} catch (err) {
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/components/Shared/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Navbar = () => {
const [isModalOpen, setIsModalOpen] = useState(false);
const [isScrolled, setIsScrolled] = useState(false);
const [isMenuOpen, setIsMenuOpen] = useState(false);
const token=localStorage.getItem("token");
const location = useLocation();
const navigate = useNavigate(); // Correctly initialize useNavigate

Expand Down Expand Up @@ -36,8 +37,12 @@ const Navbar = () => {
};

const handleLogout = () => {
setisloggedIn(false); // Set isLoggedIn to false on confirmation
// setisloggedIn(false); // Set isLoggedIn to false on confirmation
//managing log in , logout using jwt tokens
localStorage.removeItem("token");
setIsModalOpen(false); // Close the modal
setIsMenuOpen(false) // after getting logged out close the menu if it is open
navigate("/login");//navigate to login after get logged out
};

const isHomePage = location.pathname === '/';
Expand Down Expand Up @@ -96,7 +101,7 @@ const Navbar = () => {
</div>

<div className="hidden md:flex font-semibold Poppins text-lg">
{isloggedIn ? (
{token ? (
<button
className={`${baseTextColorClass} ${hoverTextColorClass} px-4 py-1 rounded-md border-2 border-black bg-beige shadow-[4px_4px_0px_0px_black] font-semibold text-[#323232]`}
type="button"
Expand Down Expand Up @@ -175,7 +180,7 @@ const Navbar = () => {
{item.name}
</Link>
))}
{isloggedIn ? (
{token ? (
<button
className={`block w-full text-left px-4 py-3 rounded-md text-base font-semibold transition duration-300
${mobileMenuBaseTextColorClass} hover:bg-amber-300 hover:text-black`}
Expand Down

0 comments on commit b40129b

Please sign in to comment.