Still working on Auth State

This commit is contained in:
2019-10-02 17:53:20 -04:00
parent dcd03d7888
commit 5df28e0e77
12 changed files with 363 additions and 60 deletions

View File

@@ -1,11 +1,22 @@
import React from 'react'
import { Route, Redirect} from 'react-router-dom';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
const AuthRoute = ({ component: Component, authenticated, ...rest}) => (
const AuthRoute = ({ component: Component, authenticated, ...rest }) => (
<Route
{...rest}
render = {(props) => authenticated === true ? <Redirect to='/home'/> : <Component {...props} />}
render={(props) =>
authenticated === true ? <Redirect to='/home'/> : <Component {...props} />}
/>
)
);
export default AuthRoute;
const mapStateToProps = (state) => ({
authenticated: state.user.authenticated
});
AuthRoute.propTypes = {
user: PropTypes.object
}
export default connect(mapStateToProps)(AuthRoute);