From ad468a7b0f7ad704d8fa9d34c7d1d999fa868e3c Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Wed, 10 Jul 2024 22:01:38 +0200 Subject: [PATCH 1/5] fix unauth conditon for onboarding modal --- src/libs/Navigation/NavigationRoot.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index a225831b56ff..18cd68d17629 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -87,7 +87,7 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N const initialState = useMemo(() => { // If the user haven't completed the flow, we want to always redirect them to the onboarding flow. - if (!hasCompletedGuidedSetupFlow) { + if (!hasCompletedGuidedSetupFlow && authenticated) { const {adaptedState} = getAdaptedStateFromPath(ROUTES.ONBOARDING_ROOT, linkingConfig.config); return adaptedState; } From 1d90fe82bfb6b143c10645689bfabee8fc6460a3 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Thu, 11 Jul 2024 10:20:38 +0200 Subject: [PATCH 2/5] add condition for browser back --- .../AppNavigator/createCustomStackNavigator/CustomRouter.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts index 5b3cefb63a2d..b65b0e433554 100644 --- a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts +++ b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts @@ -9,6 +9,7 @@ import linkingConfig from '@libs/Navigation/linkingConfig'; import getAdaptedStateFromPath from '@libs/Navigation/linkingConfig/getAdaptedStateFromPath'; import type {NavigationPartialRoute, RootStackParamList, State} from '@libs/Navigation/types'; import {isCentralPaneName, isOnboardingFlowName} from '@libs/NavigationUtils'; +import * as Session from '@userActions/Session'; import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; @@ -119,6 +120,7 @@ function shouldPreventReset(state: StackNavigationState, action: function CustomRouter(options: ResponsiveStackNavigatorRouterOptions) { const stackRouter = StackRouter(options); + const isAuthenticated = Session.hasAuthToken(); return { ...stackRouter, @@ -128,7 +130,7 @@ function CustomRouter(options: ResponsiveStackNavigatorRouterOptions) { return state; }, getStateForAction(state: StackNavigationState, action: CommonActions.Action | StackActionType, configOptions: RouterConfigOptions) { - if (shouldPreventReset(state, action)) { + if (shouldPreventReset(state, action) && isAuthenticated) { return state; } return stackRouter.getStateForAction(state, action, configOptions); From 54cf1a7a8ee3f344b680adc3ef679aa4343da0ca Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Thu, 11 Jul 2024 12:54:18 +0200 Subject: [PATCH 3/5] cleanup --- .../createCustomStackNavigator/CustomRouter.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts index b65b0e433554..2500f1427cb9 100644 --- a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts +++ b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts @@ -102,6 +102,12 @@ function compareAndAdaptState(state: StackNavigationState) { } function shouldPreventReset(state: StackNavigationState, action: CommonActions.Action | StackActionType) { + const isAuthenticated = Session.hasAuthToken(); + + if (!isAuthenticated) { + return false; + } + if (action.type !== CONST.NAVIGATION_ACTIONS.RESET || !action?.payload) { return false; } @@ -120,7 +126,6 @@ function shouldPreventReset(state: StackNavigationState, action: function CustomRouter(options: ResponsiveStackNavigatorRouterOptions) { const stackRouter = StackRouter(options); - const isAuthenticated = Session.hasAuthToken(); return { ...stackRouter, @@ -130,7 +135,7 @@ function CustomRouter(options: ResponsiveStackNavigatorRouterOptions) { return state; }, getStateForAction(state: StackNavigationState, action: CommonActions.Action | StackActionType, configOptions: RouterConfigOptions) { - if (shouldPreventReset(state, action) && isAuthenticated) { + if (shouldPreventReset(state, action)) { return state; } return stackRouter.getStateForAction(state, action, configOptions); From b7cb4965e4d88af98a1d9b00764830192f2859e2 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Thu, 11 Jul 2024 13:44:02 +0200 Subject: [PATCH 4/5] add conditon for empty state, change condition to public domain user --- .../createCustomStackNavigator/CustomRouter.ts | 7 ------- src/libs/Navigation/NavigationRoot.tsx | 6 +++++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts index 2500f1427cb9..5b3cefb63a2d 100644 --- a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts +++ b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts @@ -9,7 +9,6 @@ import linkingConfig from '@libs/Navigation/linkingConfig'; import getAdaptedStateFromPath from '@libs/Navigation/linkingConfig/getAdaptedStateFromPath'; import type {NavigationPartialRoute, RootStackParamList, State} from '@libs/Navigation/types'; import {isCentralPaneName, isOnboardingFlowName} from '@libs/NavigationUtils'; -import * as Session from '@userActions/Session'; import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; @@ -102,12 +101,6 @@ function compareAndAdaptState(state: StackNavigationState) { } function shouldPreventReset(state: StackNavigationState, action: CommonActions.Action | StackActionType) { - const isAuthenticated = Session.hasAuthToken(); - - if (!isAuthenticated) { - return false; - } - if (action.type !== CONST.NAVIGATION_ACTIONS.RESET || !action?.payload) { return false; } diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index 18cd68d17629..82fa3e555dbf 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -84,10 +84,14 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N const [hasCompletedGuidedSetupFlow] = useOnyx(ONYXKEYS.NVP_ONBOARDING, { selector: hasCompletedGuidedSetupFlowSelector, }); + const [user] = useOnyx(ONYXKEYS.USER); const initialState = useMemo(() => { + if (!user || user.isFromPublicDomain) { + return; + } // If the user haven't completed the flow, we want to always redirect them to the onboarding flow. - if (!hasCompletedGuidedSetupFlow && authenticated) { + if (!hasCompletedGuidedSetupFlow) { const {adaptedState} = getAdaptedStateFromPath(ROUTES.ONBOARDING_ROOT, linkingConfig.config); return adaptedState; } From 7276b07778977e35dcbd840f3105bc47a40aaff8 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Thu, 11 Jul 2024 19:02:48 +0200 Subject: [PATCH 5/5] cleanup --- src/libs/Navigation/NavigationRoot.tsx | 32 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index b596352cc215..b6263ff80d38 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -1,6 +1,7 @@ import type {NavigationState} from '@react-navigation/native'; import {DefaultTheme, findFocusedRoute, NavigationContainer} from '@react-navigation/native'; import React, {useContext, useEffect, useMemo, useRef} from 'react'; +import {useOnyx} from 'react-native-onyx'; import HybridAppMiddleware from '@components/HybridAppMiddleware'; import {ScrollOffsetContext} from '@components/ScrollOffsetContextProvider'; import useActiveWorkspace from '@hooks/useActiveWorkspace'; @@ -12,6 +13,7 @@ import Log from '@libs/Log'; import {getPathFromURL} from '@libs/Url'; import {updateLastVisitedPath} from '@userActions/App'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import AppNavigator from './AppNavigator'; import getPolicyIDFromState from './getPolicyIDFromState'; @@ -77,20 +79,28 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N const {isSmallScreenWidth} = useWindowDimensions(); const {setActiveWorkspaceID} = useActiveWorkspace(); -<<<<<<< HEAD - const [hasCompletedGuidedSetupFlow] = useOnyx(ONYXKEYS.NVP_ONBOARDING, { - selector: hasCompletedGuidedSetupFlowSelector, - }); const [user] = useOnyx(ONYXKEYS.USER); - const initialState = useMemo(() => { - if (!user || user.isFromPublicDomain) { - return; - } - // If the user haven't completed the flow, we want to always redirect them to the onboarding flow. - if (!hasCompletedGuidedSetupFlow) { - const {adaptedState} = getAdaptedStateFromPath(ROUTES.ONBOARDING_ROOT, linkingConfig.config); + const initialState = useMemo( + () => { + if (!user || user.isFromPublicDomain) { + return; + } + + if (!lastVisitedPath) { + return undefined; + } + + const path = initialUrl ? getPathFromURL(initialUrl) : null; + + // For non-nullable paths we don't want to set initial state + if (path) { + return; + } + const {adaptedState} = getAdaptedStateFromPath(lastVisitedPath, linkingConfig.config); + return adaptedState; + }, // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps [], );