misc_pterodactyl-panel/resources/scripts/components/elements/AuthenticatedRoute.tsx
2022-11-25 13:25:03 -07:00

18 lines
527 B
TypeScript

import type { ReactNode } from 'react';
import { Navigate, useLocation } from 'react-router-dom';
import { useStoreState } from '@/state/hooks';
function AuthenticatedRoute({ children }: { children?: ReactNode }): JSX.Element {
const isAuthenticated = useStoreState(state => !!state.user.data?.uuid);
const location = useLocation();
if (isAuthenticated) {
return <>{children}</>;
}
return <Navigate to="/auth/login" state={{ from: location.pathname }} />;
}
export default AuthenticatedRoute;