Files
bigcapital/packages/webapp/src/components/Guards/EnsureAuthenticated.tsx
2024-05-03 16:00:31 +02:00

23 lines
503 B
TypeScript

// @ts-nocheck
import React from 'react';
import { Redirect } from 'react-router-dom';
import { useIsAuthenticated } from '@/hooks/state';
interface EnsureAuthenticatedProps {
children: React.ReactNode;
redirectTo?: string;
}
export function EnsureAuthenticated({
children,
redirectTo = '/auth/login',
}: EnsureAuthenticatedProps) {
const isAuthenticated = useIsAuthenticated();
return isAuthenticated ? (
<>{children}</>
) : (
<Redirect to={{ pathname: redirectTo }} />
);
}