diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2021-09-26 05:46:13 +0200 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2021-09-26 21:35:57 +0200 |
commit | a7f6524c6b052f4d207525c813436ca12c929f00 (patch) | |
tree | 7fc9613b969cc0696bad3afd38a6c5d44d50eeb6 /app/javascript/flavours/glitch/util | |
parent | 36221107784ad26735ca2703d4d597c90eacf526 (diff) |
[Glitch] Change routing paths to use usernames in web UI
Port 52e5c07948c4c91b73062846e1f19ea278ec0e24 to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
Diffstat (limited to 'app/javascript/flavours/glitch/util')
-rw-r--r-- | app/javascript/flavours/glitch/util/api.js | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/app/javascript/flavours/glitch/util/api.js b/app/javascript/flavours/glitch/util/api.js index c59a24518..90d8465ef 100644 --- a/app/javascript/flavours/glitch/util/api.js +++ b/app/javascript/flavours/glitch/util/api.js @@ -12,21 +12,35 @@ export const getLinks = response => { return LinkHeader.parse(value); }; -let csrfHeader = {}; +const csrfHeader = {}; -function setCSRFHeader() { +const setCSRFHeader = () => { const csrfToken = document.querySelector('meta[name=csrf-token]'); + if (csrfToken) { csrfHeader['X-CSRF-Token'] = csrfToken.content; } -} +}; ready(setCSRFHeader); +const authorizationHeaderFromState = getState => { + const accessToken = getState && getState().getIn(['meta', 'access_token'], ''); + + if (!accessToken) { + return {}; + } + + return { + 'Authorization': `Bearer ${accessToken}`, + }; +}; + export default getState => axios.create({ - headers: Object.assign(csrfHeader, getState ? { - 'Authorization': `Bearer ${getState().getIn(['meta', 'access_token'], '')}`, - } : {}), + headers: { + ...csrfHeader, + ...authorizationHeaderFromState(getState), + }, transformResponse: [function (data) { try { |