import React from "react";
import { Redirect, Route, useLocation } from "react-router-dom";

function PrivateRoute({ component: Component, isAuthorized, ...rest }) {
  const location = useLocation();

  return (
    <Route
      {...rest}
      render={(props) =>
        isAuthorized === true ? (
          <Component {...props} />
        ) : (
          <Redirect to={`/signin?redirect=${location.pathname}`} />
        )
      }
    />
  );
}

export default PrivateRoute;
