Skip to content

Commit 607f80c

Browse files
committed
ADD_HTTP_HEADERS action
1 parent 9ef8317 commit 607f80c

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

dash/dash-renderer/src/actions/api.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {mergeDeepRight, once} from 'ramda';
2-
import {getCSRFHeader, handleAsyncError, setConfigNoRefresh} from '../actions';
2+
import {getCSRFHeader, handleAsyncError, addHttpHeaders} from '../actions';
33
import {urlBase} from './utils';
44
import {MAX_AUTH_RETRIES} from './constants';
55
import {JWT_EXPIRED_MESSAGE, STATUS} from '../constants/constants';
@@ -33,7 +33,7 @@ const request = {GET, POST};
3333
export default function apiThunk(endpoint, method, store, id, body) {
3434
return async (dispatch, getState) => {
3535
let {config, hooks} = getState();
36-
let configChanged = false;
36+
let newHeaders = null;
3737

3838
const url = `${urlBase(config)}${endpoint}`;
3939

@@ -76,14 +76,15 @@ export default function apiThunk(endpoint, method, store, id, body) {
7676
)
7777
);
7878
if (newJwt) {
79+
newHeaders = {
80+
Authorization: `Bearer ${newJwt}`
81+
};
82+
7983
config = mergeDeepRight(config, {
8084
fetch: {
81-
headers: {
82-
Authorization: `Bearer ${newJwt}`
83-
}
85+
headers: newHeaders
8486
}
8587
});
86-
configChanged = true;
8788

8889
continue;
8990
}
@@ -95,8 +96,8 @@ export default function apiThunk(endpoint, method, store, id, body) {
9596

9697
const contentType = res.headers.get('content-type');
9798

98-
if (configChanged) {
99-
dispatch(setConfigNoRefresh(config));
99+
if (newHeaders) {
100+
dispatch(addHttpHeaders(newHeaders));
100101
}
101102
setConnectionStatus(true);
102103
if (contentType && contentType.indexOf('application/json') !== -1) {

dash/dash-renderer/src/actions/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const actionList = {
66
SET_LAYOUT: 1,
77
SET_APP_LIFECYCLE: 1,
88
SET_CONFIG: 1,
9-
SET_CONFIG_NO_REFRESH: 2,
9+
ADD_HTTP_HEADERS: 2,
1010
ON_ERROR: 1,
1111
SET_HOOKS: 1
1212
};

dash/dash-renderer/src/actions/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import {getPath} from './paths';
1111
export const onError = createAction(getAction('ON_ERROR'));
1212
export const setAppLifecycle = createAction(getAction('SET_APP_LIFECYCLE'));
1313
export const setConfig = createAction(getAction('SET_CONFIG'));
14-
export const setConfigNoRefresh = createAction(
15-
getAction('SET_CONFIG_NO_REFRESH')
16-
);
14+
export const addHttpHeaders = createAction(getAction('ADD_HTTP_HEADERS'));
1715
export const setGraphs = createAction(getAction('SET_GRAPHS'));
1816
export const setHooks = createAction(getAction('SET_HOOKS'));
1917
export const setLayout = createAction(getAction('SET_LAYOUT'));
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import {getAction} from '../actions/constants';
2+
import {mergeDeepRight} from 'ramda';
23

34
export default function config(state = null, action) {
45
if (action.type === getAction('SET_CONFIG')) {
56
return action.payload;
6-
} else if (action.type === getAction('SET_CONFIG_NO_REFRESH')) {
7-
return action.payload;
7+
} else if (action.type === getAction('ADD_HTTP_HEADERS')) {
8+
return mergeDeepRight(state, {
9+
fetch: {
10+
headers: action.payload
11+
}
12+
});
813
}
914
return state;
1015
}

0 commit comments

Comments
 (0)