Exclude authorization header where unnecessary
parent
703f8c43c2
commit
0ecc46ab97
|
@ -21,7 +21,7 @@ export function updateUserInfo(): Promise<[boolean, integer]> {
|
||||||
loggedInUser = { username: 'Guest', lastSessionSlot: lastSessionSlot };
|
loggedInUser = { username: 'Guest', lastSessionSlot: lastSessionSlot };
|
||||||
return resolve([ true, 200 ]);
|
return resolve([ true, 200 ]);
|
||||||
}
|
}
|
||||||
Utils.apiFetch('account/info').then(response => {
|
Utils.apiFetch('account/info', true).then(response => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
resolve([ false, response.status ]);
|
resolve([ false, response.status ]);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -407,7 +407,7 @@ export class GameData {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bypassLogin) {
|
if (!bypassLogin) {
|
||||||
Utils.apiFetch(`savedata/get?datatype=${GameDataType.SYSTEM}`)
|
Utils.apiFetch(`savedata/get?datatype=${GameDataType.SYSTEM}`, true)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.length || response[0] !== '{') {
|
if (!response.length || response[0] !== '{') {
|
||||||
|
@ -578,7 +578,7 @@ export class GameData {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!bypassLogin) {
|
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(response => response.text())
|
||||||
.then(async response => {
|
.then(async response => {
|
||||||
if (!response.length || response[0] !== '{') {
|
if (!response.length || response[0] !== '{') {
|
||||||
|
@ -707,7 +707,7 @@ export class GameData {
|
||||||
updateUserInfo().then(success => {
|
updateUserInfo().then(success => {
|
||||||
if (success !== null && !success)
|
if (success !== null && !success)
|
||||||
return resolve(false);
|
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) {
|
if (response.ok) {
|
||||||
loggedInUser.lastSessionSlot = -1;
|
loggedInUser.lastSessionSlot = -1;
|
||||||
return resolve(true);
|
return resolve(true);
|
||||||
|
@ -795,7 +795,7 @@ export class GameData {
|
||||||
link.remove();
|
link.remove();
|
||||||
};
|
};
|
||||||
if (!bypassLogin && dataType < GameDataType.SETTINGS) {
|
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 => response.text())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.length || response[0] !== '{') {
|
if (!response.length || response[0] !== '{') {
|
||||||
|
|
12
src/utils.ts
12
src/utils.ts
|
@ -233,11 +233,15 @@ export function getCookie(cName: string): string {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function apiFetch(path: string): Promise<Response> {
|
export function apiFetch(path: string, authed: boolean = false): Promise<Response> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const sId = getCookie(sessionIdKey);
|
const request = {};
|
||||||
const headers = sId ? { 'Authorization': sId } : {};
|
if (authed) {
|
||||||
fetch(`${apiUrl}/${path}`, { headers: headers })
|
const sId = getCookie(sessionIdKey);
|
||||||
|
if (sId)
|
||||||
|
request['headers'] = { 'Authorization': sId };
|
||||||
|
}
|
||||||
|
fetch(`${apiUrl}/${path}`, request)
|
||||||
.then(response => resolve(response))
|
.then(response => resolve(response))
|
||||||
.catch(err => reject(err));
|
.catch(err => reject(err));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue