mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
23 lines
503 B
TypeScript
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 }} />
|
|
);
|
|
}
|