refresh issues

This commit is contained in:
Jake Kasper
2025-09-04 10:21:12 -05:00
parent 3ddbc32fe0
commit e4524432e7
3 changed files with 30 additions and 3 deletions

View File

@@ -48,14 +48,18 @@ const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: (failureCount, error) => {
// Don't retry on 401 (unauthorized) or 403 (forbidden)
if (error?.response?.status === 401 || error?.response?.status === 403) {
return false;
}
return failureCount < 2;
},
staleTime: 5 * 60 * 1000, // 5 minutes
cacheTime: 10 * 60 * 1000, // 10 minutes
// Always consider data stale so we refetch on mount/focus
staleTime: 0,
// Keep cache tiny and refetch aggressively
cacheTime: 60 * 1000,
refetchOnWindowFocus: true,
refetchOnReconnect: true,
refetchOnMount: 'always',
},
},
});

View File

@@ -10,6 +10,9 @@ export const apiClient = axios.create({
timeout: 10000,
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
'Pragma': 'no-cache',
'Expires': '0',
},
});
@@ -33,6 +36,15 @@ apiClient.interceptors.request.use(
if (token && token !== 'undefined' && token !== 'null') {
config.headers.Authorization = `Bearer ${token}`;
}
// Prevent browser/proxy caching of GET requests by adding a timestamp
if ((config.method || 'get').toLowerCase() === 'get') {
config.headers['Cache-Control'] = 'no-cache';
config.headers['Pragma'] = 'no-cache';
config.headers['Expires'] = '0';
const params = new URLSearchParams(config.params || {});
if (!params.has('_ts')) params.set('_ts', Date.now().toString());
config.params = Object.fromEntries(params.entries());
}
return config;
},
(error) => {