client: properly set content-type header

This commit is contained in:
Johann150 2022-11-08 20:33:30 +01:00
parent 5713f329ca
commit b2c800e654
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
3 changed files with 12 additions and 14 deletions

View file

@ -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<Account> {
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) {

View file

@ -71,6 +71,7 @@ const ok = async () => {
method: 'POST',
body: formData,
headers: {
'content-type': 'multipart/form-data',
authorization: `Bearer ${$i.token}`,
},
})

View file

@ -32,7 +32,10 @@ export const api = ((endpoint: string, data: Record<string, any> = {}, 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<string, any> = {}, 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();