{"size": 792, "ext": "js", "max_stars_repo_path": "client/src/components/PrivateRoute.js", "max_stars_repo_name": "wingstech-vishal/lms-auth", "max_stars_repo_stars_event_min_datetime": "2019-11-05T13:58:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-03T10:54:11.000Z", "max_issues_repo_path": "client/src/components/PrivateRoute.js", "max_issues_repo_name": "wingstech-vishal/lms-auth", "max_issues_repo_issues_event_min_datetime": "2019-08-03T16:04:10.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-03T16:31:10.000Z", "max_forks_repo_path": "client/src/components/PrivateRoute.js", "max_forks_repo_name": "wingstech-vishal/lms-auth", "max_forks_repo_forks_event_min_datetime": "2020-07-12T19:01:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-04T14:09:26.000Z"}
{"max_stars_count": 15, "max_issues_count": 5, "max_forks_count": 5, "avg_line_length": 23.2941176471, "max_line_length": 70, "alphanum_fraction": 0.523989899}
import React from 'react'
import PropTypes from 'prop-types'
import { Route, Redirect } from 'react-router-dom'
import UserContext from '../utils/UserContext'

const PrivateRoute = ({ component: Component, aId = 1, ...rest }) => (
  <UserContext.Consumer>
    {({ user }) => (
      <Route
        {...rest}
        render={props =>
          user.accessId >= aId ? (
            <Component {...props} />
          ) : (
            <Redirect
              to={{
                pathname: '/',
                state: { from: props.location }
              }}
            />
          )
        }
      />
    )}
  </UserContext.Consumer>
)

PrivateRoute.propTypes = {
  component: PropTypes.func.isRequired,
  location: PropTypes.object,
  aId: PropTypes.number
}
export default PrivateRoute
