add protected routes component

This commit is contained in:
NCanggoro 2023-10-03 14:52:25 +07:00
parent 4bc60a6dd3
commit f1b508685e

View File

@ -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 <Navigate to={"/"} replace />;
}
return children;
}