diff --git a/src/PrivateRouter.js b/src/PrivateRouter.js new file mode 100644 index 00000000..1419d160 --- /dev/null +++ b/src/PrivateRouter.js @@ -0,0 +1,27 @@ +import React from "react"; +import { Route, Redirect } from "react-router-dom"; + +const PrivateRoute = ({ type, exact, path, element }) => { + const isLoggedIn = localStorage.getItem("isLoggedIn"); + const isAdmin = localStorage.getItem("isAdmin"); + + if (type === "login") { + return isLoggedIn ? ( + + ) : ( + + ); + } + + if (type === "admin") { + return isAdmin ? ( + + ) : ( + + ); + } + + return ; +}; + +export default PrivateRoute;