Skip to content

Commit

Permalink
add isImpersonating in querykey (#2126)
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelfact committed May 17, 2024
1 parent 770bd03 commit 84e5131
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions api-client/adapter/react-query/react-query-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import { IFetchAdapater } from "api-client/adapter/fetch/fetch-adapter.types";
import { useReactQueryAuthAdapter } from "api-client/adapter/react-query-auth/react-query-auth-adapter";

import { useImpersonation } from "components/features/impersonation/use-impersonation";

interface IuseReactQueryAdapter<T> {
fetcher: IFetchAdapater<T>;
query: {
queryKey: string[];
queryKey: (string | boolean)[];
queryFn: () => Promise<T>;
};
mutation: {
Expand All @@ -15,9 +17,10 @@ interface IuseReactQueryAdapter<T> {
}
export const useReactQueryAdapter = <T>(fetchAdapter: IFetchAdapater<T>): IuseReactQueryAdapter<T> => {
const { fetcher } = useReactQueryAuthAdapter(fetchAdapter);
const { isImpersonating } = useImpersonation();

const query = {
queryKey: fetcher.tag ? [fetcher.tag] : [],
queryKey: [...(fetcher.tag || []), isImpersonating],
queryFn: () => fetcher.request(),
};

Expand Down
4 changes: 2 additions & 2 deletions src/api/useBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export function useBaseQuery<R = unknown>({

const { enabled, ...restQueryOptions } = queryOptions;
const { isAuthenticated, getAccessTokenSilently, logout } = useAuth0();
const { getImpersonateHeaders } = useImpersonation();
const { getImpersonateHeaders, isImpersonating } = useImpersonation();

return useQuery<R>({
queryKey: [...(tags || []), resourcePath, queryParams, isAuthenticated],
queryKey: [...(tags || []), resourcePath, queryParams, isAuthenticated, isImpersonating],
queryFn: async () => {
const { options } = await getHttpOptions({
isAuthenticated,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useRestfulData/useRestfulData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export function useRestfulData<R = unknown>({
}: UseRestfulDataProps<R>) {
const { enabled, ...restQueryOptions } = queryOptions;
const { isAuthenticated, getAccessTokenSilently, logout } = useAuth0();
const { getImpersonateHeaders } = useImpersonation();
const { getImpersonateHeaders, isImpersonating } = useImpersonation();

return useQuery<R>({
queryKey: [...(queryKey || []), resourcePath, pathParam, queryParams, isAuthenticated],
queryKey: [...(queryKey || []), resourcePath, pathParam, queryParams, isAuthenticated, isImpersonating],
queryFn: async () => {
const { options } = await getHttpOptions({
isAuthenticated,
Expand Down

0 comments on commit 84e5131

Please sign in to comment.