add protected routes component
This commit is contained in:
parent
4bc60a6dd3
commit
f1b508685e
14
src/routes/ProtectedRoute.tsx
Normal file
14
src/routes/ProtectedRoute.tsx
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user