import React from "react";
import { Redirect, Route } from "react-router-dom";
import { useUserContext } from "../Contexts/UserContext";
import { useStatusContext } from "../Contexts/StatusContext";

export const ProtectedRoute = ({ render, ...others }) => {
  const { token } = useUserContext();
  const { setMessage } = useStatusContext();
  if (!token) {
    setMessage("Please sign in to access");
    return <Redirect to="/" />;
  }
  return <Route render {...others} />;
};
