Skip to content

Instantly share code, notes, and snippets.

@matthewshirley
Last active June 20, 2017 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewshirley/a6cc6a8f7bc95e731dcbc1386c67ee5c to your computer and use it in GitHub Desktop.
Save matthewshirley/a6cc6a8f7bc95e731dcbc1386c67ee5c to your computer and use it in GitHub Desktop.
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