2025-02-21 20:29:00 +00:00
|
|
|
import {
|
|
|
|
|
MutationCache,
|
|
|
|
|
QueryCache,
|
|
|
|
|
QueryClient,
|
|
|
|
|
QueryClientProvider,
|
|
|
|
|
} from "@tanstack/react-query"
|
2024-03-17 17:28:45 +01:00
|
|
|
import { RouterProvider, createRouter } from "@tanstack/react-router"
|
2025-02-19 12:00:08 +00:00
|
|
|
import React, { StrictMode } from "react"
|
2024-03-17 17:28:45 +01:00
|
|
|
import ReactDOM from "react-dom/client"
|
|
|
|
|
import { routeTree } from "./routeTree.gen"
|
2024-01-23 11:48:56 -05:00
|
|
|
|
2025-02-19 12:00:08 +00:00
|
|
|
import { ApiError, OpenAPI } from "./client"
|
2025-02-17 19:33:00 +00:00
|
|
|
import { CustomProvider } from "./components/ui/provider"
|
2024-01-23 11:48:56 -05:00
|
|
|
|
2024-03-08 14:58:36 +01:00
|
|
|
OpenAPI.BASE = import.meta.env.VITE_API_URL
|
2024-01-23 11:48:56 -05:00
|
|
|
OpenAPI.TOKEN = async () => {
|
2024-03-17 17:28:45 +01:00
|
|
|
return localStorage.getItem("access_token") || ""
|
2024-01-23 11:48:56 -05:00
|
|
|
}
|
2023-11-30 16:16:32 -05:00
|
|
|
|
2025-02-19 12:00:08 +00:00
|
|
|
const handleApiError = (error: Error) => {
|
|
|
|
|
if (error instanceof ApiError && [401, 403].includes(error.status)) {
|
|
|
|
|
localStorage.removeItem("access_token")
|
|
|
|
|
window.location.href = "/login"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const queryClient = new QueryClient({
|
|
|
|
|
queryCache: new QueryCache({
|
|
|
|
|
onError: handleApiError,
|
|
|
|
|
}),
|
|
|
|
|
mutationCache: new MutationCache({
|
|
|
|
|
onError: handleApiError,
|
|
|
|
|
}),
|
|
|
|
|
})
|
2024-02-15 17:17:26 -05:00
|
|
|
|
2025-02-18 15:02:50 +00:00
|
|
|
const router = createRouter({ routeTree })
|
2024-03-17 17:28:45 +01:00
|
|
|
declare module "@tanstack/react-router" {
|
2024-03-07 19:16:23 +01:00
|
|
|
interface Register {
|
|
|
|
|
router: typeof router
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-15 17:17:26 -05:00
|
|
|
|
2024-03-17 17:28:45 +01:00
|
|
|
ReactDOM.createRoot(document.getElementById("root")!).render(
|
2024-03-07 19:16:23 +01:00
|
|
|
<StrictMode>
|
2025-02-17 19:33:00 +00:00
|
|
|
<CustomProvider>
|
2024-03-07 19:16:23 +01:00
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
|
<RouterProvider router={router} />
|
|
|
|
|
</QueryClientProvider>
|
2025-02-17 19:33:00 +00:00
|
|
|
</CustomProvider>
|
2024-03-08 14:58:36 +01:00
|
|
|
</StrictMode>,
|
|
|
|
|
)
|