diff --git a/src/account.ts b/src/account.ts index a2ff71a6e..afb9aca35 100644 --- a/src/account.ts +++ b/src/account.ts @@ -21,7 +21,7 @@ export function updateUserInfo(): Promise<[boolean, integer]> { loggedInUser = { username: 'Guest', lastSessionSlot: lastSessionSlot }; return resolve([ true, 200 ]); } - Utils.apiFetch('account/info').then(response => { + Utils.apiFetch('account/info', true).then(response => { if (!response.ok) { resolve([ false, response.status ]); return; diff --git a/src/system/game-data.ts b/src/system/game-data.ts index e1ed38d89..1c4dbaed2 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -407,7 +407,7 @@ export class GameData { } if (!bypassLogin) { - Utils.apiFetch(`savedata/get?datatype=${GameDataType.SYSTEM}`) + Utils.apiFetch(`savedata/get?datatype=${GameDataType.SYSTEM}`, true) .then(response => response.text()) .then(response => { if (!response.length || response[0] !== '{') { @@ -578,7 +578,7 @@ export class GameData { }; if (!bypassLogin) { - Utils.apiFetch(`savedata/get?datatype=${GameDataType.SESSION}&slot=${slotId}`) + Utils.apiFetch(`savedata/get?datatype=${GameDataType.SESSION}&slot=${slotId}`, true) .then(response => response.text()) .then(async response => { if (!response.length || response[0] !== '{') { @@ -707,7 +707,7 @@ export class GameData { updateUserInfo().then(success => { if (success !== null && !success) return resolve(false); - Utils.apiFetch(`savedata/delete?datatype=${GameDataType.SESSION}&slot=${slotId}`).then(response => { + Utils.apiFetch(`savedata/delete?datatype=${GameDataType.SESSION}&slot=${slotId}`, true).then(response => { if (response.ok) { loggedInUser.lastSessionSlot = -1; return resolve(true); @@ -795,7 +795,7 @@ export class GameData { link.remove(); }; if (!bypassLogin && dataType < GameDataType.SETTINGS) { - Utils.apiFetch(`savedata/get?datatype=${dataType}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ''}`) + Utils.apiFetch(`savedata/get?datatype=${dataType}${dataType === GameDataType.SESSION ? `&slot=${slotId}` : ''}`, true) .then(response => response.text()) .then(response => { if (!response.length || response[0] !== '{') { diff --git a/src/utils.ts b/src/utils.ts index acd81f4f7..3cbbfd842 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -233,11 +233,15 @@ export function getCookie(cName: string): string { return ''; } -export function apiFetch(path: string): Promise { +export function apiFetch(path: string, authed: boolean = false): Promise { return new Promise((resolve, reject) => { - const sId = getCookie(sessionIdKey); - const headers = sId ? { 'Authorization': sId } : {}; - fetch(`${apiUrl}/${path}`, { headers: headers }) + const request = {}; + if (authed) { + const sId = getCookie(sessionIdKey); + if (sId) + request['headers'] = { 'Authorization': sId }; + } + fetch(`${apiUrl}/${path}`, request) .then(response => resolve(response)) .catch(err => reject(err)); });