Skip to content

Commit

Permalink
Force logout if unauthorized
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmohan committed Dec 10, 2024
1 parent ae2bb00 commit 536a9dd
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/react-query/queryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 536a9dd

Please sign in to comment.