Created
February 3, 2018 13:03
-
-
Save alexnm/3924353865e20a11d1159e40d48595c3 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
function withAuthentication(WrappedComponent) { | |
const ModifiedComponent = (props) => { | |
if (!props.isAuthenticated) { | |
return <Redirect to="/login" />; | |
} | |
return (<WrappedComponent { ...props } />); | |
}; | |
const mapStateToProps = (state) => ({ | |
isAuthenticated: state.session.isAuthenticated | |
}); | |
return connect(mapStateToProps)(ModifiedComponent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment