diff options
Diffstat (limited to 'animism-align/frontend/app/views/auth/auth.gate.js')
| -rw-r--r-- | animism-align/frontend/app/views/auth/auth.gate.js | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/animism-align/frontend/app/views/auth/auth.gate.js b/animism-align/frontend/app/views/auth/auth.gate.js index 498d32a..ba69256 100644 --- a/animism-align/frontend/app/views/auth/auth.gate.js +++ b/animism-align/frontend/app/views/auth/auth.gate.js @@ -1,4 +1,5 @@ import React, { Component } from 'react' +import { connect } from 'react-redux' import './auth.css' @@ -6,24 +7,49 @@ import actions from 'app/actions' import AuthLogin from './auth.login' -export default class AuthGate extends Component { +class AuthGate extends Component { constructor(props) { super(props) + actions.auth.load_access_token() } - componentDidMount() { - // actions.site.loadProject() + componentDidUpdate(prevProps) { + if (this.props.user_id !== prevProps.user_id) { + this.load() + } } - componentDidUpdate() { - + 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 ( <div className='auth'> - <AuthLogin /> + {this.props.logged_in + ? <div className="login">Logging in...</div> + : <AuthLogin onAuthenticate={this.load} /> + } </div> ) } -}
\ No newline at end of file +} + +const mapStateToProps = state => ({ + ...state.auth, +}) + +export default connect(mapStateToProps)(AuthGate) |
