feat: integrate the api for authentication

This commit is contained in:
2026-08-18 16:44:57 +07:00
parent c4abd0a1f9
commit e71ce423e2
24 changed files with 471 additions and 207 deletions
+41
View File
@@ -0,0 +1,41 @@
import { QueryClient, QueryCache } from "@tanstack/react-query"
import { ApiError } from "./api-client"
import { clearAuthToken } from "./auth-storage"
/**
* Factory function to create a new configured QueryClient instance.
*/
export function createQueryClient(): QueryClient {
let client: QueryClient
const queryCache = new QueryCache({
onError: (error) => {
if (error instanceof ApiError && error.status === 401) {
clearAuthToken()
client?.clear()
}
},
})
client = new QueryClient({
queryCache,
defaultOptions: {
queries: {
staleTime: 60_000,
gcTime: 5 * 60_000,
refetchOnWindowFocus: true,
retry: (failureCount, error) => {
if (error instanceof ApiError && error.status >= 400 && error.status < 500) {
return false
}
return failureCount < 2
},
},
mutations: {
retry: false,
},
},
})
return client
}