From 536a9dd9b6288112f7c68612870074555c3e5373 Mon Sep 17 00:00:00 2001 From: Harshith Mohan <26010946+harshithmohan@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:21:42 +0530 Subject: [PATCH] Force logout if unauthorized --- src/core/react-query/queryClient.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/core/react-query/queryClient.ts b/src/core/react-query/queryClient.ts index 28f7c4a1e..3f573b13c 100644 --- a/src/core/react-query/queryClient.ts +++ b/src/core/react-query/queryClient.ts @@ -2,6 +2,8 @@ import { QueryClient } from '@tanstack/react-query'; import { isAxiosError } from 'axios'; import toast from '@/components/Toast'; +import Events from '@/core/events'; +import store from '@/core/store'; import type { QueryKey } from '@tanstack/react-query'; import type { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'; @@ -29,6 +31,14 @@ const queryClient = new QueryClient({ errorMessage = `Error ${error.message}`; } + if ( + isAxiosError(error) && (error.request as XMLHttpRequest).responseURL.endsWith('/Settings') + && errorStatus === 401 + ) { + store.dispatch({ type: Events.AUTH_LOGOUT }); + return false; + } + if (errorStatus !== 404 && failureCount < 4) return true; // 1 initial request + retry 4 times toast.error(errorHeader, errorMessage);