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.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/api/utils/auth.js b/src/api/utils/auth.js
new file mode 100644
index 000000000..47ac94c19
--- /dev/null
+++ b/src/api/utils/auth.js
@@ -0,0 +1,24 @@
1import { remote } from 'electron';
2import localStorage from 'mobx-localstorage';
3
4const { app } = remote;
5
6export const prepareAuthRequest = (options, auth = true) => {
7 const request = Object.assign(options, {
8 mode: 'cors',
9 headers: Object.assign({
10 'Content-Type': 'application/json',
11 'X-Franz-Source': 'desktop',
12 'X-Franz-Version': app.getVersion(),
13 'X-Franz-platform': process.platform,
14 'X-Franz-Timezone-Offset': new Date().getTimezoneOffset(),
15 'X-Franz-System-Locale': app.getLocale(),
16 }, options.headers),
17 });
18
19 if (auth) {
20 request.headers.Authorization = `Bearer ${localStorage.getItem('authToken')}`;
21 }
22
23 return request;
24};