From f14be3378bc67af4ee6163e5c6b74d956565f067 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Tue, 20 Aug 2024 16:14:07 +0530 Subject: [PATCH 1/2] Navigate to session expired page instead of showing notification --- src/Utils/request/handleResponse.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/request/handleResponse.ts b/src/Utils/request/handleResponse.ts index 9f85b50a68d..b45ffa10b06 100644 --- a/src/Utils/request/handleResponse.ts +++ b/src/Utils/request/handleResponse.ts @@ -27,7 +27,7 @@ export default function handleResponse( // Handle session expiry if (error?.detail === "Authentication credentials were not provided.") { - notify?.Error({ msg: "Session expired. Please Login again." }); + navigate(`/session-expired?redirect=${window.location.href}`); return; } From fc961f2d6cf63a103a319fc4a6956e45cbc88884 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Wed, 21 Aug 2024 15:47:33 +0530 Subject: [PATCH 2/2] fix edge cases and prevent recursive redirections to session expired route --- src/Utils/request/handleResponse.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Utils/request/handleResponse.ts b/src/Utils/request/handleResponse.ts index b45ffa10b06..905417ad0e2 100644 --- a/src/Utils/request/handleResponse.ts +++ b/src/Utils/request/handleResponse.ts @@ -20,14 +20,15 @@ export default function handleResponse( // Other Errors between 400-599 (inclusive) if (res.status >= 400 && res.status < 600) { - // Invalid token - if (!silent && error?.code === "token_not_valid") { - navigate(`/session-expired?redirect=${window.location.href}`); - } - - // Handle session expiry - if (error?.detail === "Authentication credentials were not provided.") { - navigate(`/session-expired?redirect=${window.location.href}`); + // Handle invalid token / session expiry + if ( + !silent && + (error?.code === "token_not_valid" || + error?.detail === "Authentication credentials were not provided.") + ) { + if (!location.pathname.startsWith("/session-expired")) { + navigate(`/session-expired?redirect=${window.location.href}`); + } return; }