Bachelorthesis_Code/frontend/src/auth/PrivateRoute.js

18 lines
373 B
JavaScript
Raw Normal View History

import { Redirect, Route } from "react-router-dom";
import { useAuth } from "./AuthProvider";
const PrivateRoute = ({ component: Component, ...rest }) => {
const [logged] = useAuth();
return (
<Route
{...rest}
render={(props) =>
logged ? <Component {...props} /> : <Redirect to="/login" />
}
/>
);
};
2021-06-23 01:40:37 +00:00
export default PrivateRoute;