Skip to content

Instantly share code, notes, and snippets.

@itaditya
Forked from alexnm/withAuthentication.jsx
Created February 8, 2018 04:18
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 itaditya/2d90504608c55bf89e7feaa3900a92e1 to your computer and use it in GitHub Desktop.
Save itaditya/2d90504608c55bf89e7feaa3900a92e1 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