{"size": 955, "ext": "js", "max_stars_repo_path": "client/src/components/PrivateRoute.js", "max_stars_repo_name": "woolsey2316/eLearn", "max_stars_repo_stars_event_min_datetime": "2022-03-12T18:03:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T18:03:54.000Z", "max_issues_repo_path": "client/src/components/PrivateRoute.js", "max_issues_repo_name": "woolsey2316/eLearn", "max_issues_repo_issues_event_min_datetime": "2020-12-04T20:55:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T22:43:58.000Z", "max_forks_repo_path": "client/src/components/PrivateRoute.js", "max_forks_repo_name": "woolsey2316/eLearn", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 27, "max_forks_count": null, "avg_line_length": 30.8064516129, "max_line_length": 81, "alphanum_fraction": 0.6157068063}
import React from 'react'
import { Route, Redirect } from 'react-router'
import { LoginPage } from './LoginPage'
/* 
  url paths are protected by redirecting the user to the /login page if
  the user is not logged in. A user is determined to be logged in if there 
  is a user object in local storage. It is possible to manually add a user object
  using browser dev tools, however this fake user would not be able to fetch
  data from the server api because a valid jwt token is required.
*/

export const PrivateRoute = ({ children: Children, ...rest }) => {
  const loggedIn = localStorage.getItem('EMAIL') ? true : false
  console.log("logged in? " + loggedIn)
  return (
    <Route
      {...rest}
      render={(props) =>
        loggedIn ? (
          Children
        ) : (
          <Redirect
            to={{ pathname: '/login', state: { from: props.location } }}
            component={LoginPage}
          />
        )
      }
    />
  )
  }
