import React from 'react' import { Route, RouteProps, Redirect } from 'react-router-dom'; import { useAuth } from './auth-context'; export const PrivateRoute: React.FC = ({component: Component, children, ...rest}) => { const { isAuthenticated } = useAuth(); return { if(isAuthenticated) { if(Component) { return ; } else if(children) { return <>{children}; } } else { return ; } }} /> }; export const AuthRoute: React.FC = ({ component: Component, children, ...rest}) => { const { isAuthenticated } = useAuth(); return { if(isAuthenticated) { const { from } = props.location.state ?? { from: '/my-account.html'}; return ; } else { if(Component) { return ; } else if(children) { return <>{children}; } } }} /> };