aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/utils/auth.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/utils/auth.js')
-rw-r--r--src/api/utils/auth.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/api/utils/auth.js b/src/api/utils/auth.js
index e493b2962..527c68840 100644
--- a/src/api/utils/auth.js
+++ b/src/api/utils/auth.js
@@ -1,7 +1,11 @@
1import localStorage from 'mobx-localstorage'; 1import localStorage from 'mobx-localstorage';
2import { ferdiLocale, ferdiVersion } from '../../environment'; 2import { ferdiLocale, ferdiVersion } from '../../environment';
3 3
4export const prepareAuthRequest = (options = { method: 'GET' }, auth = true) => { 4export const prepareAuthRequest = (
5 // eslint-disable-next-line unicorn/no-object-as-default-parameter
6 options = { method: 'GET' },
7 auth = true,
8) => {
5 const request = Object.assign(options, { 9 const request = Object.assign(options, {
6 mode: 'cors', 10 mode: 'cors',
7 headers: { 11 headers: {
@@ -16,12 +20,13 @@ export const prepareAuthRequest = (options = { method: 'GET' }, auth = true) =>
16 }); 20 });
17 21
18 if (auth) { 22 if (auth) {
19 request.headers.Authorization = `Bearer ${localStorage.getItem('authToken')}`; 23 request.headers.Authorization = `Bearer ${localStorage.getItem(
24 'authToken',
25 )}`;
20 } 26 }
21 27
22 return request; 28 return request;
23}; 29};
24 30
25export const sendAuthRequest = (url, options, auth) => ( 31export const sendAuthRequest = (url, options, auth) =>
26 window.fetch(url, prepareAuthRequest(options, auth)) 32 window.fetch(url, prepareAuthRequest(options, auth));
27);