misc_pterodactyl-panel/resources/scripts/components/elements/PermissionRoute.tsx

27 lines
666 B
TypeScript
Raw Normal View History

2022-11-25 20:25:03 +00:00
import type { ReactNode } from 'react';
import { ServerError } from '@/components/elements/ScreenBlock';
2022-11-25 20:25:03 +00:00
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}</>;
}
2022-11-25 20:25:03 +00:00
return <ServerError title="Access Denied" message="You do not have permission to access this page." />;
}
2022-11-25 20:25:03 +00:00
export default PermissionRoute;