26 lines
507 B
JavaScript
26 lines
507 B
JavaScript
import React from 'react';
|
|
import { Redirect, Route } from 'react-router-dom';
|
|
|
|
import { useAuth } from '../../helpers/authContext';
|
|
|
|
|
|
// TODO Make sure it's used, else delete it and remove message in App
|
|
const PublicRoute = ({ component: Component, ...rest }) => {
|
|
const isAuthenticated = useAuth();
|
|
|
|
return (
|
|
<Route
|
|
{...rest}
|
|
render={(props) =>
|
|
isAuthenticated ? (
|
|
<Redirect to='/dashboard' />
|
|
) : (
|
|
<Component {...props} />
|
|
)
|
|
}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default PublicRoute;
|