github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/blockapps-ba-master/ui/src/components/EnsureAuthenticated/index.js (about) 1 import { Component } from 'react'; 2 import { connect } from 'react-redux'; 3 import { browserHistory } from 'react-router'; 4 5 class EnsureAuthenticated extends Component { 6 componentDidMount() { 7 if(!this.props.authenticated) { 8 browserHistory.replace('/login'); 9 } 10 } 11 12 render() { 13 if(this.props.authenticated) { 14 return this.props.children; 15 } 16 else { 17 return null; 18 } 19 } 20 } 21 22 function mapStateToProps(state) { 23 return { 24 authenticated: state.login.authenticated 25 } 26 } 27 28 export default connect(mapStateToProps)(EnsureAuthenticated);