Skip to content

Commit

Permalink
feat: trigger BOOKS_QUERY re-execution on token change
Browse files Browse the repository at this point in the history
  • Loading branch information
amalv committed Jan 4, 2024
1 parent d1c26f4 commit c82d6f1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },

Check failure on line 60 in src/components/LibraryPage/components/Books/hooks/useBooks.ts

View workflow job for this annotation

GitHub Actions / deploy

Object literal may only specify known properties, and 'token' does not exist in type 'BooksVars'.

Check failure on line 60 in src/components/LibraryPage/components/Books/hooks/useBooks.ts

View workflow job for this annotation

GitHub Actions / deploy

Object literal may only specify known properties, and 'token' does not exist in type 'BooksVars'.
context: {
headers: token ? { authorization: `Bearer ${token}` } : {},
},
Expand All @@ -67,7 +66,6 @@ export const useBooks = ({ search, limit }: UseBooksProps) => {

useEffect(() => {
if (token && token !== tokenRef.current) {
console.log("token changed");
refetch();
}
tokenRef.current = token;
Expand Down
1 change: 0 additions & 1 deletion src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c82d6f1

Please sign in to comment.