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

export default function AuthRoute({ children, ...rest }) {
  // TODO: replace with actual Auth data from redux later
  const auth = true;
  return (
    <Route
      {...rest}
      render={({ location }) => {
        console.log(location);
        if (auth) {
          if (location.pathname === "/login") {
            return <Redirect to="/" />;
          } else {
            return children;
          }
        } else if (location.pathname !== "/login") {
          return <Redirect to="/login" />;
        }
        return children;
      }}
    />
  );
}
