diff --git a/packages/apps/human-app/frontend/src/api/hooks/use-access-token-refresh.ts b/packages/apps/human-app/frontend/src/api/hooks/use-access-token-refresh.ts index 3a7b272677..15fc0553fb 100644 --- a/packages/apps/human-app/frontend/src/api/hooks/use-access-token-refresh.ts +++ b/packages/apps/human-app/frontend/src/api/hooks/use-access-token-refresh.ts @@ -13,10 +13,10 @@ export function useAccessTokenRefresh() { const navigate = useNavigate(); const { user, signOut } = useAuth(); - const mutation = useMutation({ - mutationFn: async (params?: RefreshAccessTokenParams) => { + return useMutation({ + mutationFn: async (params: RefreshAccessTokenParams = {}) => { const throwExpirationModalOnSignOut = - params?.throwExpirationModalOnSignOut ?? true; + params.throwExpirationModalOnSignOut ?? true; try { await authService.refreshAccessToken(); @@ -37,18 +37,4 @@ export function useAccessTokenRefresh() { id: 'refresh-access-token', }, }); - - return { - refreshAccessToken: ( - params?: RefreshAccessTokenParams, - options?: Parameters[1] - ) => { - mutation.mutate(params, options); - }, - refreshAccessTokenAsync: ( - params?: RefreshAccessTokenParams, - options?: Parameters[1] - ) => mutation.mutateAsync(params, options), - isRefreshingAccessToken: mutation.isPending, - }; } diff --git a/packages/apps/human-app/frontend/src/modules/worker/hcaptcha-labeling/hooks/enable-hcaptcha-labeling.ts b/packages/apps/human-app/frontend/src/modules/worker/hcaptcha-labeling/hooks/enable-hcaptcha-labeling.ts index 15718a5692..b78813f61b 100644 --- a/packages/apps/human-app/frontend/src/modules/worker/hcaptcha-labeling/hooks/enable-hcaptcha-labeling.ts +++ b/packages/apps/human-app/frontend/src/modules/worker/hcaptcha-labeling/hooks/enable-hcaptcha-labeling.ts @@ -7,12 +7,12 @@ import * as hCaptchaLabelingService from '../services/hcaptcha-labeling.service' export function useEnableHCaptchaLabelingMutation() { const navigate = useNavigate(); - const { refreshAccessTokenAsync } = useAccessTokenRefresh(); + const { mutateAsync: refreshAccessTokenAsync } = useAccessTokenRefresh(); const mutation = useMutation({ mutationFn: async () => { const result = await hCaptchaLabelingService.enableHCaptchaLabeling(); - await refreshAccessTokenAsync(); + await refreshAccessTokenAsync({}); return result; }, onSuccess: () => { diff --git a/packages/apps/human-app/frontend/src/modules/worker/hooks/use-register-address.ts b/packages/apps/human-app/frontend/src/modules/worker/hooks/use-register-address.ts index f0d9d622a6..bd1b5f8d5e 100644 --- a/packages/apps/human-app/frontend/src/modules/worker/hooks/use-register-address.ts +++ b/packages/apps/human-app/frontend/src/modules/worker/hooks/use-register-address.ts @@ -15,7 +15,7 @@ interface RegisterAddressCallbacks { function useRegisterAddressMutation(callbacks: RegisterAddressCallbacks) { const { user, updateUserData } = useAuth(); - const { refreshAccessTokenAsync } = useAccessTokenRefresh(); + const { mutateAsync: refreshAccessTokenAsync } = useAccessTokenRefresh(); const { address, chainId, signMessage } = useWalletConnect(); const { prepareSignature } = usePrepareSignature( PrepareSignatureType.REGISTER_ADDRESS @@ -37,7 +37,7 @@ function useRegisterAddressMutation(callbacks: RegisterAddressCallbacks) { // wallet address is part of the JWT payload // so we need to refresh the token after the address is registered await profileService.registerAddress({ address, chainId, signature }); - await refreshAccessTokenAsync(); + await refreshAccessTokenAsync({}); updateUserData({ wallet_address: address, }); diff --git a/packages/apps/human-app/frontend/src/modules/worker/profile/components/identity-verification-control.tsx b/packages/apps/human-app/frontend/src/modules/worker/profile/components/identity-verification-control.tsx index 23b63457d3..cbbb106d4c 100644 --- a/packages/apps/human-app/frontend/src/modules/worker/profile/components/identity-verification-control.tsx +++ b/packages/apps/human-app/frontend/src/modules/worker/profile/components/identity-verification-control.tsx @@ -47,8 +47,10 @@ export function IdentityVerificationControl({ const { t } = useTranslation(); const { isIdvAlreadyInProgress, idvStarted, idvStartIsPending, startIdv } = useStartIdv(); - const { refreshAccessTokenAsync, isRefreshingAccessToken } = - useAccessTokenRefresh(); + const { + mutateAsync: refreshAccessTokenAsync, + isPending: isRefreshingAccessToken, + } = useAccessTokenRefresh(); const { updateUserData } = useAuth(); const { colorPalette } = useColorMode(); @@ -64,7 +66,7 @@ export function IdentityVerificationControl({ }, CHECK_STATUS_COOLDOWN_TIME); try { - await refreshAccessTokenAsync(); + await refreshAccessTokenAsync({}); const accessToken = browserAuthProvider.getAccessToken(); if (!accessToken) { diff --git a/packages/apps/human-app/frontend/src/shared/contexts/generic-auth-context.tsx b/packages/apps/human-app/frontend/src/shared/contexts/generic-auth-context.tsx index eae4bd27f5..15b5158301 100644 --- a/packages/apps/human-app/frontend/src/shared/contexts/generic-auth-context.tsx +++ b/packages/apps/human-app/frontend/src/shared/contexts/generic-auth-context.tsx @@ -65,6 +65,8 @@ export function createAuthProvider(config: { const validUserData = schema.parse(userData); + queryClient.setDefaultOptions({ queries: { enabled: true } }); + setAuthState({ user: validUserData, status: 'success' }); browserAuthProvider.signOutSubscription = displayExpirationModal; diff --git a/packages/apps/human-app/frontend/src/shared/contexts/jwt-expiration-check.tsx b/packages/apps/human-app/frontend/src/shared/contexts/jwt-expiration-check.tsx index 7526c43f6c..7c4f920abc 100644 --- a/packages/apps/human-app/frontend/src/shared/contexts/jwt-expiration-check.tsx +++ b/packages/apps/human-app/frontend/src/shared/contexts/jwt-expiration-check.tsx @@ -12,7 +12,7 @@ export function JWTExpirationCheck({ const checksOnProfile = useRef(0); const auth = useAuth(); const location = useLocation(); - const { refreshAccessToken } = useAccessTokenRefresh(); + const { mutate: refreshAccessToken } = useAccessTokenRefresh(); useEffect(() => { if (location.pathname.includes('profile') && auth.user) {