Handle token refresh errors and tell the user the token has expired

This commit is contained in:
Calli
2024-05-19 17:52:01 +03:00
parent 5cf1605a72
commit 793f71476b
3 changed files with 19 additions and 1 deletions

View File

@@ -61,7 +61,16 @@ const Home = () => {
};
const refreshSession = (characters: AccessToken[]) => {
return Promise.all(characters.map((c) => refreshToken(c)));
return Promise.all(
characters.map(async (c) => {
try {
const refreshed = await refreshToken(c);
return { ...refreshed, invalidToken: false };
} catch (e) {
return { ...c, invalidToken: true };
}
}),
);
};
const handleCallback = async (
@@ -89,6 +98,7 @@ const Home = () => {
): Promise<AccessToken[]> =>
Promise.all(
characters.map(async (c) => {
if (c.invalidToken) return { ...c, planets: [] };
const planets = await getPlanets(c);
const planetsWithInfo: PlanetWithInfo[] = await Promise.all(
planets.map(async (p) => ({