23 lines
432 B
JavaScript
23 lines
432 B
JavaScript
import React from 'react';
|
|
import { Redirect, Route } from 'react-router-dom';
|
|
|
|
import { useAuth } from '../helpers/authContext';
|
|
|
|
const PrivateRoute = ({ component: Component, ...rest }) => {
|
|
const { isAuthenticated } = useAuth();
|
|
|
|
return (
|
|
<Route
|
|
render={(props) =>
|
|
isAuthenticated ? (
|
|
<Component {...rest} {...props} />
|
|
) : (
|
|
<Redirect to='/login' />
|
|
)
|
|
}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default PrivateRoute;
|