mirror of
https://github.com/fastapi/full-stack-fastapi-template.git
synced 2026-11-03 12:29:42 +00:00
a8f1ba0e70
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import {
|
|
MutationCache,
|
|
QueryCache,
|
|
QueryClient,
|
|
QueryClientProvider,
|
|
} from "@tanstack/react-query"
|
|
import { createRouter, RouterProvider } from "@tanstack/react-router"
|
|
import { AxiosError } from "axios"
|
|
import { StrictMode } from "react"
|
|
import ReactDOM from "react-dom/client"
|
|
import { client } from "./client/client.gen"
|
|
import { ThemeProvider } from "./components/theme-provider"
|
|
import { Toaster } from "./components/ui/sonner"
|
|
import "./index.css"
|
|
import { routeTree } from "./routeTree.gen"
|
|
|
|
client.setConfig({
|
|
baseURL: import.meta.env.VITE_API_URL ?? "",
|
|
auth: () => localStorage.getItem("access_token") || "",
|
|
})
|
|
|
|
const handleApiError = (error: Error) => {
|
|
if (
|
|
error instanceof AxiosError &&
|
|
[401, 403].includes(error.response?.status ?? 0)
|
|
) {
|
|
localStorage.removeItem("access_token")
|
|
window.location.href = "/login"
|
|
}
|
|
}
|
|
const queryClient = new QueryClient({
|
|
queryCache: new QueryCache({
|
|
onError: handleApiError,
|
|
}),
|
|
mutationCache: new MutationCache({
|
|
onError: handleApiError,
|
|
}),
|
|
})
|
|
|
|
const router = createRouter({ routeTree })
|
|
declare module "@tanstack/react-router" {
|
|
interface Register {
|
|
router: typeof router
|
|
}
|
|
}
|
|
|
|
ReactDOM.createRoot(document.getElementById("root")!).render(
|
|
<StrictMode>
|
|
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
|
|
<QueryClientProvider client={queryClient}>
|
|
<RouterProvider router={router} />
|
|
<Toaster richColors closeButton />
|
|
</QueryClientProvider>
|
|
</ThemeProvider>
|
|
</StrictMode>,
|
|
)
|