diff --git a/lib/www/client/source/src/store/modules/api/actions.js b/lib/www/client/source/src/store/modules/api/actions.js index 6be81d9..459f308 100644 --- a/lib/www/client/source/src/store/modules/api/actions.js +++ b/lib/www/client/source/src/store/modules/api/actions.js @@ -1,5 +1,5 @@ -async function api ({state, commit, dispatch}, [resource, init = {}, cb]) { +async function api ({state, getters, commit, dispatch}, [resource, init = {}, cb]) { try { commit("queueRequest"); if (init && init.hasOwnProperty("body")) { @@ -9,9 +9,16 @@ async function api ({state, commit, dispatch}, [resource, init = {}, cb]) { "Content-Type": "application/json" } } - if (typeof init.body != "string") { - init.body = JSON.stringify(init.body); - } + } + if (!init.headers) { + init.headers = {}; + } + // We also send Authorization: Bearer … + if (getters.jwt) { + init.headers["Authorization"] = "Bearer "+getters.jwt; + } + if (typeof init.body != "string") { + init.body = JSON.stringify(init.body); } const url = /^https?:\/\//i.test(resource) ? resource : (state.apiUrl + resource); const res = await fetch(url, init);