Commit 15c80ea9 authored by tom's avatar tom

fix API fetch from next.js

parent 7335000f
...@@ -16,11 +16,12 @@ export default function fetchFactory( ...@@ -16,11 +16,12 @@ export default function fetchFactory(
return function fetch(url: string, init?: RequestInit): Promise<Response> { return function fetch(url: string, init?: RequestInit): Promise<Response> {
const csrfToken = _req.headers['x-csrf-token']; const csrfToken = _req.headers['x-csrf-token'];
const authToken = _req.headers['Authorization']; const authToken = _req.headers['Authorization'];
const apiToken = _req.cookies[cookies.NAMES.API_TOKEN];
const headers = { const headers = {
accept: _req.headers['accept'] || 'application/json', accept: _req.headers['accept'] || 'application/json',
'content-type': _req.headers['content-type'] || 'application/json', 'content-type': _req.headers['content-type'] || 'application/json',
cookie: `${ cookies.NAMES.API_TOKEN }=${ _req.cookies[cookies.NAMES.API_TOKEN] }`, cookie: apiToken ? `${ cookies.NAMES.API_TOKEN }=${ apiToken }` : '',
...(csrfToken ? { 'x-csrf-token': String(csrfToken) } : {}), ...(csrfToken ? { 'x-csrf-token': String(csrfToken) } : {}),
...(authToken ? { Authorization: String(authToken) } : {}), ...(authToken ? { Authorization: String(authToken) } : {}),
}; };
...@@ -31,6 +32,11 @@ export default function fetchFactory( ...@@ -31,6 +32,11 @@ export default function fetchFactory(
req: _req, req: _req,
}); });
httpLogger.logger.info({
message: 'API request headers',
headers,
});
const body = (() => { const body = (() => {
const _body = init?.body; const _body = init?.body;
if (!_body) { if (!_body) {
......
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