Exclude authorization header where unnecessary
This commit is contained in:
parent
703f8c43c2
commit
0ecc46ab97
|
@ -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;
|
||||
|
|
|
@ -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] !== '{') {
|
||||
|
|
12
src/utils.ts
12
src/utils.ts
|
@ -233,11 +233,15 @@ export function getCookie(cName: string): string {
|
|||
return '';
|
||||
}
|
||||
|
||||
export function apiFetch(path: string): Promise<Response> {
|
||||
export function apiFetch(path: string, authed: boolean = false): Promise<Response> {
|
||||
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));
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue