p00002/components/privateRoute.jsx
2024-09-07 07:52:09 -04:00

26 lines
773 B
JavaScript

import React from "react";
//import { StaticRouter } from "react-router-dom/server";
import { Link } from "react-router-dom";
import Login from "./login";
// Function to check if the user is authenticated (You can implement this based on your authentication method)
const PrivateRoute = ({ component: Component }) => {
const isAuthenticated = () => {
// Check if the user is authenticated (e.g., check for a valid authentication token in local storage)
return localStorage.getItem("authToken") !== null;
};
return isAuthenticated() ? (
<Link component={Component} to="/dashboard">
{" "}
Dashboard{" "}
</Link>
) : (
<Link component={Login} to="/login">
{" "}
Login{" "}
</Link>
);
};
export default PrivateRoute;