From b2c800e65497467295dfcfbcd05faa9d1c8f6ce6 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 8 Nov 2022 20:33:30 +0100 Subject: [PATCH] client: properly set content-type header --- packages/client/src/account.ts | 15 +++------------ packages/client/src/components/cropper-dialog.vue | 1 + packages/client/src/os.ts | 10 ++++++++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/client/src/account.ts b/packages/client/src/account.ts index c10dcfb06..0f4e828c4 100644 --- a/packages/client/src/account.ts +++ b/packages/client/src/account.ts @@ -32,12 +32,8 @@ export async function signout() { const registration = await navigator.serviceWorker.ready; const push = await registration.pushManager.getSubscription(); if (push) { - await fetch(`${apiUrl}/sw/unregister`, { - method: 'POST', - body: JSON.stringify({ - i: $i.token, - endpoint: push.endpoint, - }), + await api('sw/unregister', { + endpoint: push.endpoint, }); } } @@ -79,12 +75,7 @@ export async function removeAccount(id: Account['id']) { function fetchAccount(token: string): Promise { return new Promise((done, fail) => { // Fetch user - fetch(`${apiUrl}/i`, { - method: 'POST', - body: JSON.stringify({ - i: token, - }), - }) + api('i') .then(res => res.json()) .then(res => { if (res.error) { diff --git a/packages/client/src/components/cropper-dialog.vue b/packages/client/src/components/cropper-dialog.vue index 034b3f9e7..bb9ce8c25 100644 --- a/packages/client/src/components/cropper-dialog.vue +++ b/packages/client/src/components/cropper-dialog.vue @@ -71,6 +71,7 @@ const ok = async () => { method: 'POST', body: formData, headers: { + 'content-type': 'multipart/form-data', authorization: `Bearer ${$i.token}`, }, }) diff --git a/packages/client/src/os.ts b/packages/client/src/os.ts index a6707b3d3..1f700e93d 100644 --- a/packages/client/src/os.ts +++ b/packages/client/src/os.ts @@ -32,7 +32,10 @@ export const api = ((endpoint: string, data: Record = {}, token?: s body: JSON.stringify(data), credentials: 'omit', cache: 'no-cache', - headers: authorization ? { authorization } : {}, + headers: { + 'content-type': 'application/json', + ...(authorization ? { authorization } : {}), + }, }).then(async (res) => { const body = res.status === 204 ? null : await res.json(); @@ -69,7 +72,10 @@ export const apiGet = ((endpoint: string, data: Record = {}, token? method: 'GET', credentials: 'omit', cache: 'default', - headers: authorization ? { authorization } : {}, + headers: { + 'content-type': 'application/json', + ...(authorization ? { authorization } : {}), + }, }).then(async (res) => { const body = res.status === 204 ? null : await res.json();