Add authentication pages and routing;
This commit is contained in:
parent
18bd3aa7e9
commit
ef85ff6d24
13 changed files with 661 additions and 28 deletions
|
|
@ -1,11 +1,23 @@
|
|||
|
||||
import { Link } from "react-router-dom";
|
||||
const Header = () => {
|
||||
|
||||
return (
|
||||
<header>
|
||||
<h1><a href="#0">Header</a></h1>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<header>
|
||||
<h1>
|
||||
{" "}
|
||||
<Link to="/">ISSP5</Link>{" "}
|
||||
</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li>
|
||||
<Link to="/">Home</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to="/login">Login</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
|
||||
export default Header;
|
||||
export default Header;
|
||||
|
|
|
|||
14
src/components/ProtectedRoute.jsx
Normal file
14
src/components/ProtectedRoute.jsx
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { Navigate } from "react-router-dom";
|
||||
|
||||
const ProtectedRoute = ({ children }) => {
|
||||
const isLoggedIn = localStorage.getItem("isLoggedIn") === "true";
|
||||
|
||||
if (!isLoggedIn) {
|
||||
// Redirect to login if not logged in
|
||||
return <Navigate to="/login" replace />;
|
||||
}
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
export default ProtectedRoute;
|
||||
Loading…
Add table
Add a link
Reference in a new issue