import React, { Component } from 'react' import { connect } from 'react-redux' import './auth.css' import actions from 'app/actions' import AuthLogin from './auth.login' class AuthGate extends Component { constructor(props) { super(props) actions.auth.load_access_token() } componentDidUpdate(prevProps) { if (this.props.user_id !== prevProps.user_id) { this.load() } } load() { if (!this.props.user_id) return actions.user.show(this.props.user_id) .then(() => { actions.site.loadProject() }).catch(error => { if (error.status_code === 401) { actions.auth.logout() } else { console.error(error) } }) } render() { if (this.props.user) { return this.props.children } return (