Skip to content

Instantly share code, notes, and snippets.

@alexnm
Created February 3, 2018 13:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexnm/3924353865e20a11d1159e40d48595c3 to your computer and use it in GitHub Desktop.
Save alexnm/3924353865e20a11d1159e40d48595c3 to your computer and use it in GitHub Desktop.
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