# HG changeset patch # User ymh # Date 1497889406 -7200 # Node ID 96543c395baa6ba5b1935b5106dcd54ef97950c5 # Parent a2761c5be5513c8b973b30e8b393328d2253cca0 Use token in storage state, not in localStorage diff -r a2761c5be551 -r 96543c395baa client/src/APIClient.js --- a/client/src/APIClient.js Mon Jun 19 17:56:43 2017 +0200 +++ b/client/src/APIClient.js Mon Jun 19 18:23:26 2017 +0200 @@ -1,6 +1,7 @@ class APIClient { - constructor(baseURL) { + constructor(baseURL, store) { this.baseURL = baseURL; + this.store = store; } createRequest = (method, uri, data, headers) => { @@ -21,8 +22,14 @@ return new Request(this.baseURL + uri, options); } + getToken = () => { + const state = this.store.getState(); + return state.get('token'); + } + hasToken = () => { - const token = localStorage.getItem('token'); + //const token = localStorage.getItem('token'); + const token = this.getToken(); return token !== null; } @@ -30,7 +37,8 @@ createAuthorizedRequest = (method, uri, data) => { var headers = new Headers(), - token = localStorage.getItem('token') || ''; + //token = localStorage.getItem('token') || ''; + token = this.getToken() || ''; headers.append("Authorization", "JWT " + token); return this.createRequest(method, uri, data, headers); diff -r a2761c5be551 -r 96543c395baa client/src/sagas/index.js --- a/client/src/sagas/index.js Mon Jun 19 17:56:43 2017 +0200 +++ b/client/src/sagas/index.js Mon Jun 19 18:23:26 2017 +0200 @@ -120,7 +120,7 @@ token: response.token, }]; - yield actions.map(action => put(action)) + yield all(actions.map(action => put(action))) } catch(e) { yield put({ type: types.AUTH_LOGIN_ERROR, error: e }); diff -r a2761c5be551 -r 96543c395baa client/src/store/configureStore.js --- a/client/src/store/configureStore.js Mon Jun 19 17:56:43 2017 +0200 +++ b/client/src/store/configureStore.js Mon Jun 19 18:23:26 2017 +0200 @@ -40,7 +40,7 @@ )); const context = { - client: new APIClient(config.apiRootUrl) + client: new APIClient(config.apiRootUrl, store) } saga.run(rootSaga, context);