import { Navigate } from "react-router-dom";
import React from "react";

interface AuthorizedRouteProps {
  children: React.ReactNode;
  isAuthorized: boolean;
}

export function AuthorizedRoute({
  children,
  isAuthorized,
}: AuthorizedRouteProps): JSX.Element {
  if (!isAuthorized) {
    return <Navigate to="/unauthorized" />;
  }

  return children as React.ReactElement;
}
