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

26 lines
666 B
TypeScript

import type { ReactNode } from 'react';
import { ServerError } from '@/components/elements/ScreenBlock';
import { usePermissions } from '@/plugins/usePermissions';
interface Props {
children?: ReactNode;
permission?: string | string[];
}
function PermissionRoute({ children, permission }: Props): JSX.Element {
if (permission === undefined) {
return <>{children}</>;
}
const can = usePermissions(permission);
if (can.filter(p => p).length > 0) {
return <>{children}</>;
}
return <ServerError title="Access Denied" message="You do not have permission to access this page." />;
}
export default PermissionRoute;