From 38cf36e165e3fcd240ac2e1938461ca0544c4b8e Mon Sep 17 00:00:00 2001 From: Itay Mizeretz Date: Sun, 25 Feb 2018 17:06:40 +0200 Subject: [PATCH] append options to existsing ones --- .../cc/ui/src/services/AuthService.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/monkey_island/cc/ui/src/services/AuthService.js b/monkey_island/cc/ui/src/services/AuthService.js index ea5db3b8b..c5a474ebf 100644 --- a/monkey_island/cc/ui/src/services/AuthService.js +++ b/monkey_island/cc/ui/src/services/AuthService.js @@ -40,7 +40,7 @@ export default class AuthService { }) }; - _authFetch = (url, options) => { + _authFetch = (url, options = {}) => { const headers = { 'Accept': 'application/json', 'Content-Type': 'application/json' @@ -50,15 +50,21 @@ export default class AuthService { headers['Authorization'] = 'JWT ' + this._getToken(); } - return fetch(url, { - headers, - ...options - }).then(res => { - if (res.status === 401) { - this._removeToken(); + if (options.hasOwnProperty('headers')) { + for (let header in headers) { + options['headers'][header] = headers[header]; } - return res; - }); + } else { + options['headers'] = headers; + } + + return fetch(url, options) + .then(res => { + if (res.status === 401) { + this._removeToken(); + } + return res; + }); }; loggedIn() {