summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/auth/auth.gate.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-03-05 21:34:34 +0100
committerJules Laplace <julescarbon@gmail.com>2021-03-05 21:34:34 +0100
commit88d092e21a4ea296ce804ef416683807df4b7d38 (patch)
tree53e85f1e415cfc298f814d52029516c1a33de712 /animism-align/frontend/app/views/auth/auth.gate.js
parent0907418ce2c6ca498b02e8e514e4945d79750467 (diff)
change password. log in
Diffstat (limited to 'animism-align/frontend/app/views/auth/auth.gate.js')
-rw-r--r--animism-align/frontend/app/views/auth/auth.gate.js40
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)