summaryrefslogtreecommitdiff
path: root/app/client
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-09-17 02:25:36 +0200
committerJules Laplace <julescarbon@gmail.com>2018-09-17 02:25:36 +0200
commit4c18946614657a9f8955408e514172a74eacc28e (patch)
tree1fa92e5e7f798203d40e846bd8577b0459af1fcd /app/client
parent7ef59901e08b6610f134c696876695cf52061f48 (diff)
logging i
Diffstat (limited to 'app/client')
-rw-r--r--app/client/api/crud.fetch.js7
-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
5 files changed, 19 insertions, 10 deletions
diff --git a/app/client/api/crud.fetch.js b/app/client/api/crud.fetch.js
index a160175..716ab3e 100644
--- a/app/client/api/crud.fetch.js
+++ b/app/client/api/crud.fetch.js
@@ -10,7 +10,7 @@ export function crud_fetch(type, tag) {
},
show: id => {
- return fetch(uri + id)
+ return fetch(uri + id, _get_headers(), _get_headers())
.then(req => req.json())
.catch(error)
},
@@ -45,6 +45,7 @@ function _get_url(_url, data) {
function _get_headers() {
return {
method: 'GET',
+ credentials: 'same-origin',
headers: {
'Accept': 'application/json',
},
@@ -54,6 +55,7 @@ export function post(data) {
return {
method: 'POST',
body: JSON.stringify(data),
+ credentials: 'same-origin',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
@@ -64,6 +66,7 @@ export function postBody(data) {
return {
method: 'POST',
body: data,
+ credentials: 'same-origin',
headers: {
'Accept': 'application/json',
},
@@ -73,6 +76,7 @@ export function put(data) {
return {
method: 'PUT',
body: JSON.stringify(data),
+ credentials: 'same-origin',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
@@ -83,6 +87,7 @@ export function destroy(data) {
return {
method: 'DELETE',
body: JSON.stringify(data),
+ credentials: 'same-origin',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
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}>