import * as React from 'react'; import { Redirect, Route, RouteProps, RouteComponentProps } from "react-router-dom"; import { withAuthenticationContext, AuthenticationContextProps } from './AuthenticationContext'; import * as Authentication from './Authentication'; import { WithFeaturesProps, withFeatures } from '../features/FeaturesContext'; interface UnauthenticatedRouteProps extends RouteProps, AuthenticationContextProps, WithFeaturesProps { component: React.ComponentType> | React.ComponentType; } type RenderComponent = (props: RouteComponentProps) => React.ReactNode; class UnauthenticatedRoute extends Route { public render() { const { authenticationContext, component: Component, features, ...rest } = this.props; const renderComponent: RenderComponent = (props) => { if (authenticationContext.me) { return (); } if (Component) { return (); } } return ( ); } } export default withFeatures(withAuthenticationContext(UnauthenticatedRoute));