From ff9e6cf3308ab0a16f3ae9fdd4ac000d948d6c21 Mon Sep 17 00:00:00 2001 From: Ren Date: Sun, 8 Oct 2023 06:55:58 +0700 Subject: [PATCH] Remove auth token on 403 --- src/pages/_app.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 8cc14c0..1678923 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -1,7 +1,14 @@ import BaseLayout from "@/components/layout/BaseLayout"; import { ContestContextProvider } from "@/components/module/ContestContext"; +import { authTokenAtom } from "@/components/states"; import "@/styles/globals.css"; -import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { + QueryCache, + QueryClient, + QueryClientProvider, +} from "@tanstack/react-query"; +import { getDefaultStore } from "jotai"; +import { HTTPError } from "ky-universal"; import { NextPage } from "next"; import type { AppProps } from "next/app"; import React, { ReactElement, ReactNode } from "react"; @@ -28,6 +35,16 @@ export default function App({ Component, pageProps }: AppPropsWithLayout) { refetchInterval: 10000, }, }, + queryCache: new QueryCache({ + onError(error, query) { + if (error instanceof HTTPError) { + if (error.response.status === 403) { + const jotaiStore = getDefaultStore(); + jotaiStore.set(authTokenAtom, ""); + } + } + }, + }), }) ); return (