summaryrefslogtreecommitdiff
path: root/app/client/auth/auth.gate.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/client/auth/auth.gate.js')
-rw-r--r--app/client/auth/auth.gate.js42
1 files changed, 32 insertions, 10 deletions
diff --git a/app/client/auth/auth.gate.js b/app/client/auth/auth.gate.js
index e7a9940..8bedfa9 100644
--- a/app/client/auth/auth.gate.js
+++ b/app/client/auth/auth.gate.js
@@ -1,9 +1,10 @@
import { h, Component } from 'preact';
// import PropTypes from 'prop-types';
-import { BrowserRouter, Route } from 'react-router-dom'
+import { BrowserRouter, Route, Switch, Redirect, withRouter } from 'react-router-dom'
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
-import { Redirect } from 'react-router-dom';
+
+import * as authActions from './auth.actions';
import Login from './login.component';
import Logout from './logout.component';
@@ -11,23 +12,43 @@ import Signup from './signup.component';
import { randint } from '../util/math'
-class AuthGate extends Component {
+class AuthRouter extends Component {
render(){
- if (this.props.auth.isAuthenticated) return children
return (
<BrowserRouter>
<div>
- <div className="spinfx"></div>
- <Route exact path='/' component={Login} />
- <Route exact path='/login' component={Login} />
- <Route exact path='/logout' component={Logout} />
- <Route exact path='/signup' component={Signup} />
+ <div className="diamond"></div>
+ <Switch>
+ <Route exact path='/' component={Login} />
+ <Route exact path='/login' component={Login} />
+ <Route exact path='/logout' component={Logout} />
+ <Route exact path='/signup' component={Signup} />
+ <Route component={() => {
+ props.actions.setReturnTo(props.location.pathname)
+ return (
+ <Redirect to="/login" />
+ )
+ }} />
+ </Switch>
</div>
</BrowserRouter>
)
}
componentDidMount(){
- document.querySelector('.spinfx').style.backgroundImage = 'linear-gradient(' + (randint(40)-5) + 'deg, #fde, #ffe)'
+ document.querySelector('.diamond').style.backgroundImage = 'linear-gradient(' + (randint(40)-5) + 'deg, #fde, #ffe)'
+ }
+}
+
+class AuthGate extends Component {
+ render(){
+ if (!this.props.auth.initialized) {
+ return <div className='loading'>Loading</div>
+ }
+ if (this.props.auth.isAuthenticated) return children
+ return <AuthRouter {...this.props} />
+ }
+ componentDidMount(){
+ this.props.actions.checkin(history)
}
}
@@ -36,6 +57,7 @@ const mapStateToProps = (state) => ({
});
const mapDispatchToProps = (dispatch) => ({
+ actions: bindActionCreators(authActions, dispatch)
});
export default connect(mapStateToProps, mapDispatchToProps)(AuthGate);