diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-09-17 12:54:23 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-09-17 12:54:23 +0200 |
| commit | f3f84961eb9ddf3dacfb3e4bf5c56504303c048f (patch) | |
| tree | 7fe27edce878ca6bd11ebe163c034311d57f936f /app/client/auth | |
| parent | 15e5df27774fef8d976c74b6ec7bcf8f878e5834 (diff) | |
redirects work
Diffstat (limited to 'app/client/auth')
| -rw-r--r-- | app/client/auth/auth.actions.js | 8 | ||||
| -rw-r--r-- | app/client/auth/auth.gate.js | 14 | ||||
| -rw-r--r-- | app/client/auth/login.component.js | 7 |
3 files changed, 17 insertions, 12 deletions
diff --git a/app/client/auth/auth.actions.js b/app/client/auth/auth.actions.js index aa46d1b..956e7b0 100644 --- a/app/client/auth/auth.actions.js +++ b/app/client/auth/auth.actions.js @@ -49,7 +49,7 @@ export function login(username, password) { dispatch(setCurrentUser(data.user)) }) .catch(error => { - console.error(error) + console.error('login error', error) dispatch(setError(true)) }) } @@ -66,7 +66,7 @@ export function signup(data) { dispatch(setCurrentUser(data.user)) }) .catch(error => { - console.error(error) + console.error('signup error', error) dispatch(initialized()) }) } @@ -83,7 +83,7 @@ export function checkin() { dispatch(setCurrentUser(data.user)) }) .catch(error => { - console.error('err', error) + console.error('checkin error', error) dispatch(initialized()) }) } @@ -100,7 +100,7 @@ export function logout() { dispatch(initialized()) }) .catch(error => { - console.error('err', error) + console.error('logout error', error) dispatch(clearCurrentUser()) dispatch(initialized()) }) diff --git a/app/client/auth/auth.gate.js b/app/client/auth/auth.gate.js index 087dfc6..574feb3 100644 --- a/app/client/auth/auth.gate.js +++ b/app/client/auth/auth.gate.js @@ -4,6 +4,7 @@ import { BrowserRouter, Route, Switch, Redirect, withRouter } from 'react-router import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; +import { history } from '../store' import * as authActions from './auth.actions'; import Login from './login.component'; @@ -44,7 +45,18 @@ class AuthGate extends Component { if (!this.props.auth.initialized) { return <div className='loading'>Loading</div> } - if (this.props.auth.isAuthenticated) return <div>{this.props.children}</div> + if (this.props.auth.isAuthenticated) { + if (this.props.auth.returnTo) { + let { returnTo } = this.props.auth + if (!returnTo || returnTo.match(/(login|logout|signup)/i)) { + returnTo = '/' + } + this.props.actions.setReturnTo(null) + history.push(returnTo) + return <div>Launching app</div> + } + return <div>{this.props.children}</div> + } return <AuthRouter {...this.props} /> } componentDidMount(){ diff --git a/app/client/auth/login.component.js b/app/client/auth/login.component.js index 2ef01a6..1123f75 100644 --- a/app/client/auth/login.component.js +++ b/app/client/auth/login.component.js @@ -30,13 +30,6 @@ class Login extends Component { this.props.actions.login(this.state.username, this.state.password) } render(){ - if (this.props.auth.isAuthenticated) { - let { returnTo } = this.props.auth - if (!returnTo || returnTo.match(/(login|logout|signup)/i)) { - returnTo = '/' - } - return <Redirect to={returnTo} /> - } return ( <form onSubmit={this.handleSubmit}> <h1>Log in</h1><br /> |
