forked from FoundKeyGang/FoundKey
client: properly set content-type header
This commit is contained in:
parent
5713f329ca
commit
b2c800e654
3 changed files with 12 additions and 14 deletions
|
@ -32,12 +32,8 @@ export async function signout() {
|
||||||
const registration = await navigator.serviceWorker.ready;
|
const registration = await navigator.serviceWorker.ready;
|
||||||
const push = await registration.pushManager.getSubscription();
|
const push = await registration.pushManager.getSubscription();
|
||||||
if (push) {
|
if (push) {
|
||||||
await fetch(`${apiUrl}/sw/unregister`, {
|
await api('sw/unregister', {
|
||||||
method: 'POST',
|
endpoint: push.endpoint,
|
||||||
body: JSON.stringify({
|
|
||||||
i: $i.token,
|
|
||||||
endpoint: push.endpoint,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,12 +75,7 @@ export async function removeAccount(id: Account['id']) {
|
||||||
function fetchAccount(token: string): Promise<Account> {
|
function fetchAccount(token: string): Promise<Account> {
|
||||||
return new Promise((done, fail) => {
|
return new Promise((done, fail) => {
|
||||||
// Fetch user
|
// Fetch user
|
||||||
fetch(`${apiUrl}/i`, {
|
api('i')
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify({
|
|
||||||
i: token,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
|
|
|
@ -71,6 +71,7 @@ const ok = async () => {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
headers: {
|
headers: {
|
||||||
|
'content-type': 'multipart/form-data',
|
||||||
authorization: `Bearer ${$i.token}`,
|
authorization: `Bearer ${$i.token}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -32,7 +32,10 @@ export const api = ((endpoint: string, data: Record<string, any> = {}, token?: s
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
headers: authorization ? { authorization } : {},
|
headers: {
|
||||||
|
'content-type': 'application/json',
|
||||||
|
...(authorization ? { authorization } : {}),
|
||||||
|
},
|
||||||
}).then(async (res) => {
|
}).then(async (res) => {
|
||||||
const body = res.status === 204 ? null : await res.json();
|
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',
|
method: 'GET',
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
cache: 'default',
|
cache: 'default',
|
||||||
headers: authorization ? { authorization } : {},
|
headers: {
|
||||||
|
'content-type': 'application/json',
|
||||||
|
...(authorization ? { authorization } : {}),
|
||||||
|
},
|
||||||
}).then(async (res) => {
|
}).then(async (res) => {
|
||||||
const body = res.status === 204 ? null : await res.json();
|
const body = res.status === 204 ? null : await res.json();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue