import { FC, useContext, useEffect } from 'react'; import { Navigate, useLocation } from 'react-router-dom'; import { AuthenticatedContext, AuthenticatedContextValue, AuthenticationContext } from '../../contexts/authentication/context'; import { storeLoginRedirect } from '../../api/authentication'; import { RequiredChildrenProps } from '../../utils'; const RequireAuthenticated: FC = ({ children }) => { const authenticationContext = useContext(AuthenticationContext); const location = useLocation(); useEffect(() => { if (!authenticationContext.me) { storeLoginRedirect(location); } }); return authenticationContext.me ? ( {children} ) : ( ); }; export default RequireAuthenticated;