Skip to content

Commit

Permalink
Remove auth token on 403
Browse files Browse the repository at this point in the history
  • Loading branch information
rorre committed Oct 7, 2023
1 parent 127820b commit ff9e6cf
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 (
Expand Down

0 comments on commit ff9e6cf

Please sign in to comment.