From c82d6f1b3408a3c37a7c58c1a04fcd0a3f297651 Mon Sep 17 00:00:00 2001 From: amalv <1252707+amalv@users.noreply.github.com> Date: Thu, 4 Jan 2024 17:22:42 +0100 Subject: [PATCH] feat: trigger BOOKS_QUERY re-execution on token change --- src/components/LibraryPage/components/Books/hooks/useBooks.ts | 4 +--- src/contexts/AuthContext.tsx | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/components/LibraryPage/components/Books/hooks/useBooks.ts b/src/components/LibraryPage/components/Books/hooks/useBooks.ts index c0557bf..4c863b0 100644 --- a/src/components/LibraryPage/components/Books/hooks/useBooks.ts +++ b/src/components/LibraryPage/components/Books/hooks/useBooks.ts @@ -52,13 +52,12 @@ export const useBooks = ({ search, limit }: UseBooksProps) => { const { isAuthenticated } = useAuth0(); const { token } = useAuth(); const tokenRef = useRef(token); - console.log("useBooks token: ", token); const { loading, error, data, fetchMore, refetch } = useQuery< BooksData, BooksVars >(BOOKS_QUERY, { - variables: { title: search, author: search, limit, cursor: "0" }, + variables: { title: search, author: search, limit, cursor: "0", token }, context: { headers: token ? { authorization: `Bearer ${token}` } : {}, }, @@ -67,7 +66,6 @@ export const useBooks = ({ search, limit }: UseBooksProps) => { useEffect(() => { if (token && token !== tokenRef.current) { - console.log("token changed"); refetch(); } tokenRef.current = token; diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index 5629611..a85bf3b 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -33,7 +33,6 @@ const refreshToken = ( const idToken = claims.__raw; // The raw id_token localStorage.setItem("auth0.token", idToken); setToken(idToken); - console.log("refreshToken idToken:", idToken); // Add this line try { const decodedToken: DecodedToken = jwtDecode(idToken);