From d1077b220b4b0db4cdb9848b350e44f36dc820eb Mon Sep 17 00:00:00 2001 From: jinkang-0 Date: Tue, 21 May 2024 22:17:26 -0700 Subject: [PATCH] add pathname check in flow check --- src/utils/hooks.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils/hooks.ts b/src/utils/hooks.ts index c229ca87..50f50667 100644 --- a/src/utils/hooks.ts +++ b/src/utils/hooks.ts @@ -2,6 +2,7 @@ import { useCallback, useContext, useEffect, useMemo } from 'react'; import { usePathname, useRouter } from 'next/navigation'; +import CONFIG from '@/lib/configs'; import { useAuth } from './AuthProvider'; import { OnboardingContext } from './OnboardingProvider'; import { useProfile } from './ProfileProvider'; @@ -48,6 +49,8 @@ export const useScrollToTop = () => { */ export const useGuardedOnboarding = () => { const onboarding = useContext(OnboardingContext); + const pathname = usePathname(); + if (!onboarding) throw new Error( 'Component should be wrapped inside the onboarding context', @@ -57,8 +60,9 @@ export const useGuardedOnboarding = () => { const { push } = useRouter(); useEffect(() => { - if (flow.length === 0) push('/onboarding/'); - }, [flow, push]); + if (flow.length === 0 && pathname !== CONFIG.onboardingHome) + push('/onboarding/'); + }, [flow, push, pathname]); return { flow, ...rest }; };