diff --git a/template/apps/web/src/pages/_app/PageConfig/index.tsx b/template/apps/web/src/pages/_app/PageConfig/index.tsx index 10b6eb94..e8bd2b3c 100644 --- a/template/apps/web/src/pages/_app/PageConfig/index.tsx +++ b/template/apps/web/src/pages/_app/PageConfig/index.tsx @@ -1,4 +1,4 @@ -import React, { FC, Fragment, ReactElement } from 'react'; +import React, { FC, Fragment, ReactElement, useEffect } from 'react'; import { useRouter } from 'next/router'; import { accountApi } from 'resources/account'; @@ -30,15 +30,15 @@ interface PageConfigProps { const PageConfig: FC = ({ children }) => { const { route, push } = useRouter(); - const { data: account, isLoading: isAccountLoading } = accountApi.useGet({ - onSettled: () => { - if (!config.MIXPANEL_API_KEY) return; - analyticsService.init(); + const { data: account, isLoading: isAccountLoading, isSuccess, isError } = accountApi.useGet(); - analyticsService.setUser(account); - }, - }); + useEffect(() => { + if ((!isSuccess && !isError) || !config.MIXPANEL_API_KEY) return; + + analyticsService.init(); + analyticsService.setUser(account); + }, [isSuccess, isError]); if (isAccountLoading) return null; diff --git a/template/apps/web/src/resources/account/account.api.ts b/template/apps/web/src/resources/account/account.api.ts index c5441568..76817b43 100644 --- a/template/apps/web/src/resources/account/account.api.ts +++ b/template/apps/web/src/resources/account/account.api.ts @@ -1,4 +1,4 @@ -import { useMutation, useQuery } from '@tanstack/react-query'; +import { useMutation, useQuery, UseQueryOptions } from '@tanstack/react-query'; import { apiService } from 'services'; @@ -56,7 +56,7 @@ export const useResendEmail = () => mutationFn: (data: T) => apiService.post('/account/resend-email', data), }); -export const useGet = (options = {}) => +export const useGet = (options: Partial> = {}) => useQuery({ queryKey: ['account'], queryFn: () => apiService.get('/account'),