import React, { Fragment } from 'react' import { Route, RouteProps, Redirect } from 'react-router-dom'; import { SpinnerIcon } from './components/icons'; import { useAuth } from './auth-context'; export const PrivateRoute: React.FC = ({component: Component, children, ...rest}) => { const { isAuthenticated, isLoading } = useAuth(); return { if(isAuthenticated) { if(Component) { return ; } else if(children) { return <>{children}; } } else { if (isLoading) { return Loading user info... } return ; } }} /> }; export const AuthRoute: React.FC = ({ component: Component, children, ...rest}) => { const { isAuthenticated } = useAuth(); return { if(isAuthenticated) { let state = props.location.state as any; let from = '/my-account.html'; if (typeof state == 'object' && 'from' in state){ from = state.from; } return ; } else { if(Component) { return ; } else if(children) { return <>{children}; } } }} /> };