Skip to content

Commit

Permalink
modify hooks to prevent recursive checking in roles page
Browse files Browse the repository at this point in the history
  • Loading branch information
jinkang-0 committed May 23, 2024
1 parent cfcbee2 commit 1f45a95
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand All @@ -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 };
};
Expand Down

0 comments on commit 1f45a95

Please sign in to comment.