From f1b508685e17840ff40f8f07f4e5f1ad537303bb Mon Sep 17 00:00:00 2001 From: NCanggoro Date: Tue, 3 Oct 2023 14:52:25 +0700 Subject: [PATCH] add protected routes component --- src/routes/ProtectedRoute.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/routes/ProtectedRoute.tsx diff --git a/src/routes/ProtectedRoute.tsx b/src/routes/ProtectedRoute.tsx new file mode 100644 index 0000000..a3bed2c --- /dev/null +++ b/src/routes/ProtectedRoute.tsx @@ -0,0 +1,14 @@ +import { Navigate } from "react-router-dom" +import { useSelector } from "react-redux" +import { UserRootState } from "src/store/type" + + +export const ProtectedRoute = ({children}: any) => { + + const user = useSelector((state: UserRootState) => state.auth) + if(!user.is_admin) { + return ; + } + + return children; +} \ No newline at end of file