import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import { connect } from 'react-redux';

const PublicRoute = ({ component: Component, auth, ...rest }) => (
  <Route {...rest} render={props => {
    if (auth.isLoggedIn) {
      return <Redirect to={{ pathname: '/' }} />
    }

    return <Component {...props} />
  }} />
);

export default connect(
  (state) => ({ auth: state.auth })
)(PublicRoute)
