Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] add pathname check in flow check #91

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading