Last active
June 20, 2017 20:40
-
-
Save matthewshirley/a6cc6a8f7bc95e731dcbc1386c67ee5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import PropTypes from 'prop-types'; | |
import { connect } from 'react-redux'; | |
import { Route, Redirect, withRouter } from 'react-router-dom'; | |
const AuthRoute = ({ component: Component, isLoggedIn, ...rest }) => ( | |
<Route | |
{...rest} | |
render={props => (isLoggedIn === true ? <Component {...props} /> : <Redirect to={{ pathname: '/auth/login' }} />)} | |
/> | |
); | |
function mapStateToProps(state) { | |
return { | |
isLoggedIn: state.authStore.isLoggedIn, | |
}; | |
} | |
export default withRouter(connect(mapStateToProps, null)(AuthRoute)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment