{"size": 770, "ext": "js", "max_stars_repo_path": "client/src/components/ProtectedRoute.js", "max_stars_repo_name": "Code-Aditya-14/celesta2020", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/src/components/ProtectedRoute.js", "max_issues_repo_name": "Code-Aditya-14/celesta2020", "max_issues_repo_issues_event_min_datetime": "2022-03-19T06:49:27.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:13:07.000Z", "max_forks_repo_path": "client/src/components/ProtectedRoute.js", "max_forks_repo_name": "Code-Aditya-14/celesta2020", "max_forks_repo_forks_event_min_datetime": "2020-11-10T04:56:48.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T16:20:44.000Z"}
{"max_stars_count": null, "max_issues_count": 23, "max_forks_count": 12, "avg_line_length": 30.8, "max_line_length": 80, "alphanum_fraction": 0.6961038961}
import React from "react";
import { compose } from "redux";
import { connect } from "react-redux";
import { Redirect } from "react-router-dom";
import { loginUser } from "redux/actions/authActions";

class ProtectedRoute extends React.Component {
  render() {
    const Component = this.props.component;
    const user = JSON.parse(localStorage.getItem("user"));
    console.log(user);
    const isAdmin = user ? user.isAdmin : false;
    console.log(isAdmin);

    return isAdmin ? <Component /> : <Redirect to={{ pathname: "/" }} />;
  }
}
const mapStateToProps = (state) => ({
  isAuthenticated: state.auth.isAuthenticated,
  isLoading: state.auth.isLoading,
  error: state.error,
});

export default compose(connect(mapStateToProps, { loginUser }))(ProtectedRoute);
