Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

662 B
Raw Blame
import { Permission } from '@activepieces/core-utils';
import { ReactNode } from 'react';
import { Navigate } from 'react-router-dom';

import { useAuthorization } from '@/hooks/authorization-hooks';

export const RoutePermissionGuard = ({
  requiredPermissions: permission,
  children,
}: {
  children: ReactNode;
  requiredPermissions: Permission | Permission[];
}) => {
  const { checkAccess } = useAuthorization();
  const permissions = Array.isArray(permission) ? permission : [permission];
  const hasAccess = permissions.some((p) => checkAccess(p));
  if (!hasAccess) {
    return <Navigate replace={true} to="/404"></Navigate>;
  }
  return children;
};