Commit 4b9eba62 authored by tom's avatar tom

pass csrf token in header

parent 84c980b0
......@@ -13,10 +13,12 @@ export default function fetchFactory(
// first arg can be only a string
// FIXME migrate to RequestInfo later if needed
return function fetch(url: string, init?: RequestInit): Promise<Response> {
const csrfToken = _req.headers['x-csrf-token'];
const headers = {
accept: _req.headers['accept'] || 'application/json',
'content-type': _req.headers['content-type'] || 'application/json',
cookie: `${ cookies.NAMES.API_TOKEN }=${ _req.cookies[cookies.NAMES.API_TOKEN] }`,
...(csrfToken ? { 'x-csrf-token': String(csrfToken) } : {}),
};
httpLogger.logger.info({
......
......@@ -37,7 +37,7 @@ export default function useFetch() {
return _body;
}
return JSON.stringify({ ..._body, _csrf_token: token });
return JSON.stringify(_body);
})();
const reqParams = {
......@@ -45,6 +45,7 @@ export default function useFetch() {
body,
headers: {
...(isBodyAllowed && !isFormData ? { 'Content-type': 'application/json' } : undefined),
...(isBodyAllowed && token ? { 'x-csrf-token': token } : undefined),
...params?.headers,
},
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment