diff --git a/React-frontend/src/components/routes/extractorRoute.js b/React-frontend/src/components/routes/extractorRoute.js new file mode 100644 index 00000000..a49e45de --- /dev/null +++ b/React-frontend/src/components/routes/extractorRoute.js @@ -0,0 +1,23 @@ +import React from 'react'; +import { useSelector } from 'react-redux'; +import { Route, Redirect } from 'react-router-dom'; + +const extractorRoute = ({ component: Component, ...rest }) => { + const { isAuthenticated, isLoading, user } = useSelector(state => state.auth); + + return ( + + (!isLoading && !isAuthenticated) || + (!isLoading && isAuthenticated && user.role !== 'extractor') ? ( + + ) : ( + + ) + } + /> + ); +}; + +export default extractorRoute; diff --git a/React-frontend/src/components/routes/managementRoute.js b/React-frontend/src/components/routes/managementRoute.js new file mode 100644 index 00000000..cb54f552 --- /dev/null +++ b/React-frontend/src/components/routes/managementRoute.js @@ -0,0 +1,23 @@ +import React from 'react'; +import { useSelector } from 'react-redux'; +import { Route, Redirect } from 'react-router-dom'; + +const managementRoute = ({ component: Component, ...rest }) => { + const { isAuthenticated, isLoading, user } = useSelector(state => state.auth); + + return ( + + (!isLoading && !isAuthenticated) || + (!isLoading && isAuthenticated && user.role !== 'management') ? ( + + ) : ( + + ) + } + /> + ); +}; + +export default managementRoute;