diff --git a/JS/BlueskyAPI.js b/JS/BlueskyAPI.js index 7673893..7a3e733 100644 --- a/JS/BlueskyAPI.js +++ b/JS/BlueskyAPI.js @@ -559,12 +559,12 @@ export async function RefreshTokens() { let WellKnown = GetPDSWellKnown(); let body = await WellKnown.then((response) => response.json()); let header = await WellKnown.then((response) => response.headers.get("dpop-nonce")); - HandleError(body, header); + await HandleError(body, header); // Create varaibles, be aware of waits because of internet. - let DPoP = await ClientDPoPToken("POST", WellKnown.token_endpoint); + let DPoP = await ClientDPoPToken("POST", body.token_endpoint); // Token refresh let Var = await localStorage.getItem(Variables.BlueskyRefreshToken); - let Auth = await ReauthRequest(WellKnown.token_endpoint, Var, DPoP).then((response) => response.json()); + let Auth = await ReauthRequest(body.token_endpoint, Var, DPoP).then((response) => response.json()); // Save the tokens and be done await localStorage.setItem(Variables.BlueskyAccessToken, Auth.access_token); await localStorage.setItem(Variables.BlueskyRefreshToken, Auth.refresh_token); @@ -572,7 +572,7 @@ export async function RefreshTokens() { async function HandleError(body, header) { await localStorage.setItem(Variables.BlueskyNonce, header); - if (body.message.includes("claim timestamp check failed")) { + if (body.message != undefined && body.message.includes("claim timestamp check failed")) { await RefreshTokens(); } }