import React from "react" import { Route, Redirect } from "react-router" import { PropTypes } from "prop-types" import { api } from "src/API" export class ProtectedRoute extends React.Component { static propTypes = { location: PropTypes.shape({ pathname: PropTypes.string, search: PropTypes.string, }), admin: PropTypes.bool, } render(props) { const user = api.loggedInUser if (user.pending) { // If login token has not yet been confirmed, park until it is and redirect back here return ( ( )} /> ) } else { // If we are not a user or an admin go to the login page if (!user._id || (this.props.admin && !user.administrator)) { return ( ( )} /> ) } else { return } } } }