Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions src/libs/Navigation/guards/OnboardingGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {isOnboardingFlowName} from '@libs/Navigation/helpers/isNavigatorName';
import {getOnboardingInitialPath} from '@userActions/Welcome/OnboardingFlow';
import CONFIG from '@src/CONFIG';
import CONST from '@src/CONST';
import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -129,6 +130,21 @@ function shouldPreventReset(state: NavigationState, action: NavigationAction) {
return false;
}

/**
* Check if the navigation action is targeting an onboarding screen.
* This handles NAVIGATE/PUSH actions that target the OnboardingModalNavigator directly.
*/
function isNavigatingToOnboardingFlow(action: NavigationAction): boolean {
Comment thread
Beamanator marked this conversation as resolved.
if (
(action.type === CONST.NAVIGATION.ACTION_TYPE.NAVIGATE || action.type === CONST.NAVIGATION.ACTION_TYPE.PUSH) &&
(action.payload as {name?: string} | undefined)?.name === NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR
Comment thread
Beamanator marked this conversation as resolved.
Comment thread
Beamanator marked this conversation as resolved.
) {
Comment thread
Beamanator marked this conversation as resolved.
return true;
}

return false;
}

/**
* OnboardingGuard handles ONLY the core NewDot onboarding flow
*/
Expand All @@ -148,6 +164,13 @@ const OnboardingGuard: NavigationGuard = {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const isInvitedOrGroupMember = (!CONFIG.IS_HYBRID_APP && (hasNonPersonalPolicy || wasInvitedToNewDot)) ?? false;

// Redirect completed users who try to navigate to onboarding routes (e.g. via deep link)
// The OnboardingModalNavigator is not mounted when onboarding is complete, so the route would silently fail
if (isOnboardingCompleted && isNavigatingToOnboardingFlow(action)) {
Log.info('[OnboardingGuard] Redirecting completed user away from onboarding route to home');
return {type: 'REDIRECT', route: ROUTES.HOME};
}

const shouldSkipOnboarding = context.isLoading || isTransitioning || isOnboardingCompleted || isMigratedUser || isSingleEntry || needsExplanationModal || isInvitedOrGroupMember;

if (shouldSkipOnboarding) {
Expand Down
Loading
Loading