import React from 'react'
import { browserHistory } from 'react-router'

export default class EnsureLoggedIn extends React.Component {

  componentWillMount () {
    if (!this.props.isUserLogined) {
      browserHistory.replace('/login')
    }
  }

  render () {
    return this.props.isUserLogined ? this.props.children : null
  }
}

EnsureLoggedIn.propTypes = {
  isUserLogined:React.PropTypes.bool,
  children: React.PropTypes.any
}

