blob: 5e759a6b77de34c57cd55e562f6f265bdd80cca6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
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
this.props.onAuthenticate()
}
render() {
if (this.props.logged_in) {
return this.props.children
}
return (
<div className='auth'>
<AuthLogin onAuthenticate={this.load} />
</div>
)
}
}
const mapStateToProps = state => ({
...state.auth,
})
export default connect(mapStateToProps)(AuthGate)
|