From afc2072fbc111d2f3fbf93868310dce4b990ad9a Mon Sep 17 00:00:00 2001 From: hoseacodes Date: Sun, 11 Feb 2024 23:01:48 -0600 Subject: [PATCH] fix(*): add private router --- src/PrivateRouter.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/PrivateRouter.js 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;