Skip to content

Commit

Permalink
fix: A lot more refreshToken whenever it fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimple committed Jun 3, 2022
1 parent 4f3808f commit c36fd89
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/scripts/destiny2/apiClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ export class DestinyApiClient {
};

this.loadCommonSettings = async function () {
await refreshTokenIfExpired();

return new Promise(async (resolve, reject) => {
await pluginClient.GET(`${destinyApiUrl}/Settings`, await getUserToken(), (response) => {
resolve(JSON.parse(response.content));
Expand Down Expand Up @@ -383,6 +385,7 @@ export class DestinyApiClient {
this.refreshToken = async function () {
const refreshToken = await db.getItem("destinyRefreshToken");
if (refreshToken === null) {
eventEmitter.emit("destiny2-auth-refresh-failed");
return null;
}

Expand Down Expand Up @@ -448,6 +451,7 @@ export class DestinyApiClient {

resolve(profiles.Response);
} else {
self.refreshToken();
reject(result);
}
}
Expand Down Expand Up @@ -535,6 +539,7 @@ export class DestinyApiClient {

resolve(profile.Response);
} else {
self.refreshToken();
reject(result);
}
}
Expand All @@ -543,6 +548,8 @@ export class DestinyApiClient {
};

this.getLastPlayedCharacter = async function (forceRefresh = false) {
await refreshTokenIfExpired();

let _profile = self.profile;

if (forceRefresh) {
Expand Down Expand Up @@ -604,6 +611,8 @@ export class DestinyApiClient {
};

this.equipItems = async function (_lastPlayer) {
await refreshTokenIfExpired();

return new Promise(async (resolve, reject) => {
await pluginClient.POSTJson(
`${destinyApiUrl}/Destiny2/Actions/Items/EquipItems/`,
Expand All @@ -617,6 +626,7 @@ export class DestinyApiClient {
if (result.statusCode === 200) {
resolve(result.content);
} else {
self.refreshToken();
reject(result);
}
}
Expand All @@ -625,6 +635,8 @@ export class DestinyApiClient {
};

this.lockItem = async function (membershipType, characterId, itemId, lockState) {
await refreshTokenIfExpired();

return new Promise(async (resolve, reject) => {
await pluginClient.POSTJson(
`${destinyApiUrl}/Destiny2/Actions/Items/SetLockState/`,
Expand All @@ -639,6 +651,7 @@ export class DestinyApiClient {
if (result.statusCode === 200) {
resolve(result.content);
} else {
self.refreshToken();
reject(result);
}
}
Expand Down Expand Up @@ -916,6 +929,7 @@ export class DestinyApiClient {
);

while (savedAmount > 0) {
await refreshTokenIfExpired();
let historyActivityUrl = `https://www.bungie.net/Platform/Destiny2/-1/Account/${membershipId}/Character/${characterId}/Stats/Activities?count=${maxActivitiesPerFetch}&page=${page}`;
savedAmount = 0;
log("CHARACTER-HISTORY", `Loading page ${page} (${historyActivityUrl})`);
Expand All @@ -941,6 +955,7 @@ export class DestinyApiClient {
}
} catch (e) {
log("CHARACTER-HISTORY", "Failed to load character history", e, history);
self.refreshToken();
reject(history.Result.content);
}

Expand Down

0 comments on commit c36fd89

Please sign in to comment.