From 88d092e21a4ea296ce804ef416683807df4b7d38 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 5 Mar 2021 21:34:34 +0100 Subject: change password. log in --- animism-align/frontend/app/views/auth/auth.gate.js | 40 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'animism-align/frontend/app/views/auth/auth.gate.js') 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 (
- + {this.props.logged_in + ?
Logging in...
+ : + }
) } -} \ No newline at end of file +} + +const mapStateToProps = state => ({ + ...state.auth, +}) + +export default connect(mapStateToProps)(AuthGate) -- cgit v1.2.3-70-g09d2