summaryrefslogtreecommitdiff
path: root/app/client/auth
diff options
context:
space:
mode:
Diffstat (limited to 'app/client/auth')
-rw-r--r--app/client/auth/auth.actions.js9
-rw-r--r--app/client/auth/auth.gate.js4
-rw-r--r--app/client/auth/auth.reducer.js3
-rw-r--r--app/client/auth/login.component.js6
4 files changed, 13 insertions, 9 deletions
diff --git a/app/client/auth/auth.actions.js b/app/client/auth/auth.actions.js
index 8d9a819..33af206 100644
--- a/app/client/auth/auth.actions.js
+++ b/app/client/auth/auth.actions.js
@@ -45,9 +45,8 @@ export function login(username, password) {
.then(req => req.json())
.then(data => {
console.log(data)
- dispatch(setCurrentUser(data))
+ dispatch(setCurrentUser(data.user))
// dispatch(setToken(data.token))
- dispatch(checkin())
})
.catch(error => {
console.log(error)
@@ -78,13 +77,11 @@ export function checkin() {
fetch(api.checkin, put({}))
.then(req => req.json())
.then(data => {
- console.log(data)
- dispatch(setCurrentUser(data))
- console.log('set current user')
+ dispatch(setCurrentUser(data.user))
})
.catch(error => {
console.log(error)
- dispatch(initialized(true))
+ dispatch(initialized())
})
}
}
diff --git a/app/client/auth/auth.gate.js b/app/client/auth/auth.gate.js
index 4890864..087dfc6 100644
--- a/app/client/auth/auth.gate.js
+++ b/app/client/auth/auth.gate.js
@@ -44,11 +44,11 @@ class AuthGate extends Component {
if (!this.props.auth.initialized) {
return <div className='loading'>Loading</div>
}
- if (this.props.auth.isAuthenticated) return children
+ if (this.props.auth.isAuthenticated) return <div>{this.props.children}</div>
return <AuthRouter {...this.props} />
}
componentDidMount(){
- this.props.actions.checkin(history)
+ this.props.actions.checkin()
}
}
diff --git a/app/client/auth/auth.reducer.js b/app/client/auth/auth.reducer.js
index 7b3193a..80b1ec5 100644
--- a/app/client/auth/auth.reducer.js
+++ b/app/client/auth/auth.reducer.js
@@ -39,6 +39,9 @@ const auth = (state = authInitialState, action) => {
case types.auth.set_current_user:
return {
...state,
+ loading: false,
+ initialized: true,
+ isAuthenticated: true,
user: action.data,
error: null,
}
diff --git a/app/client/auth/login.component.js b/app/client/auth/login.component.js
index 3cfcb78..2ef01a6 100644
--- a/app/client/auth/login.component.js
+++ b/app/client/auth/login.component.js
@@ -31,7 +31,11 @@ class Login extends Component {
}
render(){
if (this.props.auth.isAuthenticated) {
- return <Redirect to={this.props.auth.returnTo || '/'} />
+ let { returnTo } = this.props.auth
+ if (!returnTo || returnTo.match(/(login|logout|signup)/i)) {
+ returnTo = '/'
+ }
+ return <Redirect to={returnTo} />
}
return (
<form onSubmit={this.handleSubmit}>