From 8c658246e1d6c8c3190183d026521cefd4fb56ff Mon Sep 17 00:00:00 2001 From: Steve Garon Date: Tue, 13 Jul 2021 13:44:49 +0000 Subject: [PATCH 1/2] Stop using deprecated param --- src/components/routes/login.tsx | 2 +- src/components/routes/login/reset.tsx | 2 +- src/components/routes/submit.tsx | 2 +- src/components/routes/tos.tsx | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/routes/login.tsx b/src/components/routes/login.tsx index 7c989ff25..9340ed9ef 100644 --- a/src/components/routes/login.tsx +++ b/src/components/routes/login.tsx @@ -143,7 +143,7 @@ export default function LoginScreen({ allowUserPass, allowSignup, allowPWReset, } }, onSuccess: () => { - window.location.reload(false); + window.location.reload(); } }); } diff --git a/src/components/routes/login/reset.tsx b/src/components/routes/login/reset.tsx index 823674da7..565466403 100644 --- a/src/components/routes/login/reset.tsx +++ b/src/components/routes/login/reset.tsx @@ -46,7 +46,7 @@ export function ResetPasswordNow({ buttonLoading, setButtonLoading }: ResetPassw onExit: () => setButtonLoading(false), onSuccess: () => { setDone(true); - setTimeout(() => window.location.reload(false), 7000); + setTimeout(() => window.location.reload(), 7000); } }); event.preventDefault(); diff --git a/src/components/routes/submit.tsx b/src/components/routes/submit.tsx index 49bfdd515..5a09bd214 100644 --- a/src/components/routes/submit.tsx +++ b/src/components/routes/submit.tsx @@ -153,7 +153,7 @@ function Submit() { const data = JSON.parse(api_data); if (Object.hasOwnProperty.call(data, 'api_status_code')) { if (data.api_status_code === 401) { - window.location.reload(false); + window.location.reload(); } } } catch (ex) { diff --git a/src/components/routes/tos.tsx b/src/components/routes/tos.tsx index 97ac7ca6c..0c635e505 100644 --- a/src/components/routes/tos.tsx +++ b/src/components/routes/tos.tsx @@ -46,7 +46,7 @@ export default function Tos() { function acceptTOS() { apiCall({ url: `/api/v4/user/tos/${currentUser.username}/`, - onSuccess: () => window.location.reload(false), + onSuccess: () => window.location.reload(), onEnter: () => setButtonLoading(true), onExit: () => setButtonLoading(false) }); @@ -55,7 +55,7 @@ export default function Tos() { function cancelTOS() { apiCall({ url: '/api/v4/auth/logout/', - onSuccess: () => window.location.reload(false), + onSuccess: () => window.location.reload(), onEnter: () => setButtonLoading(true), onExit: () => setButtonLoading(false) }); From 37e20347fced2c22ea7bc5cc0326eec57273824e Mon Sep 17 00:00:00 2001 From: Steve Garon Date: Tue, 13 Jul 2021 13:45:14 +0000 Subject: [PATCH 2/2] Trap unauthorized error in a better way --- src/components/hooks/useMyAPI.tsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/components/hooks/useMyAPI.tsx b/src/components/hooks/useMyAPI.tsx index 019e7c933..b078d2462 100644 --- a/src/components/hooks/useMyAPI.tsx +++ b/src/components/hooks/useMyAPI.tsx @@ -53,13 +53,7 @@ export default function useMyAPI() { // Fetch the URL fetch(url, requestOptions) - .then(res => { - if (res.status === 401 && reloadOnUnauthorize) { - // Trigger a page reload, we're not logged in anymore - window.location.reload(false); - } - return res.json(); - }) + .then(res => res.json()) .catch(err => { // eslint-disable-next-line no-console console.error(err); @@ -81,6 +75,7 @@ export default function useMyAPI() { } else if (api_data.api_status_code === 401 && reloadOnUnauthorize) { // Detect login request // Do nothing... we are reloading the page + window.location.reload(); return; } else if (api_data.api_status_code !== 200) { // Handle errors