diff options
author | 2019-03-12 13:33:37 +0100 | |
---|---|---|
committer | 2019-03-12 13:33:37 +0100 | |
commit | f4f7983315c52f01d55af2ced7c70237ae2a0af1 (patch) | |
tree | a269f125185eca89419c02f26a590307ab63adee /src/api | |
parent | Merge pull request #1329 from meetfranz/fix/windows-copy-paste (diff) | |
download | ferdium-app-f4f7983315c52f01d55af2ced7c70237ae2a0af1.tar.gz ferdium-app-f4f7983315c52f01d55af2ced7c70237ae2a0af1.tar.zst ferdium-app-f4f7983315c52f01d55af2ced7c70237ae2a0af1.zip |
add useful helpers for building standalone app features
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/utils/auth.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/api/utils/auth.js b/src/api/utils/auth.js new file mode 100644 index 000000000..d469853a5 --- /dev/null +++ b/src/api/utils/auth.js | |||
@@ -0,0 +1,28 @@ | |||
1 | import { remote } from 'electron'; | ||
2 | import localStorage from 'mobx-localstorage'; | ||
3 | |||
4 | const { app } = remote; | ||
5 | |||
6 | export 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 | }; | ||
25 | |||
26 | export const sendAuthRequest = (url, options) => ( | ||
27 | window.fetch(url, prepareAuthRequest(options)) | ||
28 | ); | ||