11import { useEffect , useRef } from 'react' ;
22import { InteractionManager } from 'react-native' ;
33import { startOnboardingFlow } from '@libs/actions/Welcome/OnboardingFlow' ;
4+ import getCurrentUrl from '@libs/Navigation/currentUrl' ;
45import Navigation from '@libs/Navigation/Navigation' ;
56import { hasCompletedGuidedSetupFlowSelector , tryNewDotOnyxSelector } from '@libs/onboardingSelectors' ;
67import { buildCannedSearchQuery } from '@libs/SearchQueryUtils' ;
8+ import { isLoggingInAsNewUser } from '@libs/SessionUtils' ;
79import isProductTrainingElementDismissed from '@libs/TooltipUtils' ;
810import CONFIG from '@src/CONFIG' ;
911import ONYXKEYS from '@src/ONYXKEYS' ;
@@ -17,12 +19,15 @@ import useOnyx from './useOnyx';
1719 * Warning: This hook should be used only once in the app
1820 */
1921function useOnboardingFlowRouter ( ) {
22+ const currentUrl = getCurrentUrl ( ) ;
2023 const [ isLoadingApp = true ] = useOnyx ( ONYXKEYS . IS_LOADING_APP , { canBeMissing : true } ) ;
2124 const [ onboardingValues , isOnboardingCompletedMetadata ] = useOnyx ( ONYXKEYS . NVP_ONBOARDING , {
2225 canBeMissing : true ,
2326 } ) ;
2427
2528 const [ account ] = useOnyx ( ONYXKEYS . ACCOUNT , { canBeMissing : true } ) ;
29+ const [ sessionEmail ] = useOnyx ( ONYXKEYS . SESSION , { canBeMissing : true , selector : ( session ) => session ?. email } ) ;
30+ const isLoggingInAsNewSessionUser = isLoggingInAsNewUser ( currentUrl , sessionEmail ) ;
2631 const startedOnboardingFlowRef = useRef ( false ) ;
2732 const [ tryNewDot , tryNewDotMetadata ] = useOnyx ( ONYXKEYS . NVP_TRY_NEW_DOT , {
2833 selector : tryNewDotOnyxSelector ,
@@ -37,6 +42,10 @@ function useOnboardingFlowRouter() {
3742 useEffect ( ( ) => {
3843 // This should delay opening the onboarding modal so it does not interfere with the ongoing ReportScreen params changes
3944 InteractionManager . runAfterInteractions ( ( ) => {
45+ // Prevent starting the onboarding flow if we are logging in as a new user with short lived token
46+ if ( currentUrl ?. includes ( ROUTES . TRANSITION_BETWEEN_APPS ) && isLoggingInAsNewSessionUser ) {
47+ return ;
48+ }
4049 if ( isLoadingApp !== false ) {
4150 return ;
4251 }
@@ -109,6 +118,8 @@ function useOnboardingFlowRouter() {
109118 dismissedProductTraining ,
110119 account ?. isFromPublicDomain ,
111120 account ?. hasAccessibleDomainPolicies ,
121+ currentUrl ,
122+ isLoggingInAsNewSessionUser ,
112123 ] ) ;
113124
114125 return { isOnboardingCompleted : hasCompletedGuidedSetupFlowSelector ( onboardingValues ) , isHybridAppOnboardingCompleted} ;
0 commit comments