import React /*, { useContext, createContext, useState }*/ from "react";
import {
  Route,
  Redirect
} from "react-router-dom";

export function PrivateRoute({ children, ...rest }) {
  let token = localStorage['token'];
  return (
    <Route
      {...rest}
      render={({ location }) => token
        ? (children)
        : (<Redirect to={{ pathname: "/login", state: { from: location } }} />)} />
  );
}
