From 207b9ae36c0f25398a9f56de3d04153d92a84fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:03:00 -0500 Subject: [PATCH] fix: manage errors extensions --- src/app/components/Checks.tsx | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/app/components/Checks.tsx b/src/app/components/Checks.tsx index 314d9657d..98fe9334c 100644 --- a/src/app/components/Checks.tsx +++ b/src/app/components/Checks.tsx @@ -9,13 +9,18 @@ import * as App from '../../stores/app'; import { CURRENT_POLICIES_AGREEMENT_INDEX } from '../../stores/app/constants'; import { PatreonAuthResponse } from '../auth/[provider]/page'; -interface Extension { - data: { - access_token: string; - account_id: number; - expires_at: number; - }; -} +type Extension = + | { + status: 'ok'; + data: { + access_token: string; + account_id: number; + expires_at: number; + }; + } + | { + status: 'error'; + }; /** * Wargaming: 14 (refresh: 7) @@ -80,11 +85,15 @@ export function Checks() { .then((response) => response.json() as Promise) .then((json) => { mutateApp((draft) => { - draft.logins.wargaming = { - id: wargaming.id, - token: json.data.access_token, - expires: json.data.expires_at * 1000, - }; + if (json.status === 'error') { + draft.logins.wargaming = undefined; + } else { + draft.logins.wargaming = { + id: wargaming.id, + token: json.data.access_token, + expires: json.data.expires_at * 1000, + }; + } }); }); }