Skip to content
4 changes: 2 additions & 2 deletions src/pages/RequireTwoFactorAuthenticationOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ function RequireTwoFactorAuthenticationOverlay() {

const handleOnPress = useCallback(() => {
if (isUserValidated) {
Navigation.navigate(ROUTES.SETTINGS_2FA_ROOT.getRoute());
Navigation.navigate(ROUTES.SETTINGS_2FA_ROOT.getRoute(Navigation.getActiveRoute()));
return;
}
Navigation.navigate(ROUTES.SETTINGS_2FA_VERIFY_ACCOUNT.getRoute({forwardTo: ROUTES.SETTINGS_2FA_ROOT.getRoute()}));
Navigation.navigate(ROUTES.SETTINGS_2FA_VERIFY_ACCOUNT.getRoute({forwardTo: ROUTES.SETTINGS_2FA_ROOT.getRoute(), backTo: Navigation.getActiveRoute()}));
}, [isUserValidated]);

if (!shouldShowRequire2FAPage || isIn2FASetupFlow) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useRoute} from '@react-navigation/native';
import React, {useMemo} from 'react';
import type {ValueOf} from 'type-fest';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
Expand All @@ -7,10 +8,13 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import useOnyx from '@hooks/useOnyx';
import {quitAndNavigateBack} from '@libs/actions/TwoFactorAuthActions';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import type {TwoFactorAuthNavigatorParamList} from '@libs/Navigation/types';
import CONST from '@src/CONST';
import type {StepCounterParams} from '@src/languages/params';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type ChildrenProps from '@src/types/utils/ChildrenProps';

type TwoFactorAuthWrapperProps = ChildrenProps & {
Expand Down Expand Up @@ -62,7 +66,9 @@ function TwoFactorAuthWrapper({stepName, title, stepCounter, onBackButtonPress,
}
}, [account, stepName]);

const defaultGoBack = () => quitAndNavigateBack(ROUTES.SETTINGS_SECURITY);
const route = useRoute<PlatformStackRouteProp<TwoFactorAuthNavigatorParamList, typeof SCREENS.TWO_FACTOR_AUTH.ROOT>>();
const backTo = route.params?.backTo;
const defaultGoBack = () => quitAndNavigateBack(backTo ?? ROUTES.SETTINGS_SECURITY);
Comment on lines +70 to +71

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do it without a dependency on backTo? Since we are moving away from the usage of backTo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShridharGoel I think we can remove the backTo param on this screen by following the “separating routes for each screen instance” guideline:
https://github.com/Expensify/App/blob/main/contributingGuides/NAVIGATION.md#separating-routes-for-each-screen-instance

However, since the backTo param for this screen is also used in other places, do you think it would be better to perform that refactor in a separate PR?

For this PR, we could focus only on fixing the navigation logic, and then address the backTo removal and route separation as a follow-up to keep the scope smaller.


return (
<ScreenWrapper
Expand Down
Loading