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

Fix: Onboarding modal shows up after refreshing page with 2FA setup when xero connected and 2FA disabled #46750

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ function Expensify({
authenticated={isAuthenticated}
lastVisitedPath={lastVisitedPath as Route}
initialUrl={initialUrl}
shouldShowRequire2FAModal={shouldShowRequire2FAModal}
/>
</SplashScreenHiddenContext.Provider>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@
}

if (!initialReportID) {
initialReportID = ReportUtils.findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom(), activeWorkspaceID)?.reportID;
const initialReport = ReportUtils.findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom(), activeWorkspaceID);
initialReportID = initialReport?.reportID ?? "";

Check failure on line 228 in src/libs/Navigation/AppNavigator/AuthScreens.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Replace `""` with `''`
Copy link
Contributor

Choose a reason for hiding this comment

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

@tushar-a-b Can you explain this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When a user logs in, initially there is no data in ONYX when 2FA is disabled with Xero (Because server not responding with any data when 2FA is required), in this case initialReportID will stay undefined and below code

initialParams={getCentralPaneScreenInitialParams(centralPaneName, initialReportID)}

will result into initialParams as r/undefined and app will treat undefined as reportId which will result into Hmm...not found page in report. To prevent this scenario, we need to avoid keeping initialReportID as undefined.
Hence above code will keep initialReportID as "" empty string when initialReportID is undefined.

This scenario is thoroughly explained in proposal's result section with video.

}

isInitialRender.current = false;
Expand Down
7 changes: 5 additions & 2 deletions src/libs/Navigation/NavigationRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type NavigationRootProps = {

/** Fired when react-navigation is ready */
onReady: () => void;

/** Flag to indicate if the require 2FA modal should be shown to the user */
shouldShowRequire2FAModal: boolean;
};

/**
Expand Down Expand Up @@ -73,7 +76,7 @@ function parseAndLogRoute(state: NavigationState) {
}
}

function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: NavigationRootProps) {
function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady, shouldShowRequire2FAModal}: NavigationRootProps) {
const firstRenderRef = useRef(true);
const theme = useTheme();
const {cleanStaleScrollOffsets} = useContext(ScrollOffsetContext);
Expand All @@ -94,7 +97,7 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N

// If the user haven't completed the flow, we want to always redirect them to the onboarding flow.
// We also make sure that the user is authenticated.
if (!hasCompletedGuidedSetupFlow && authenticated) {
if (!hasCompletedGuidedSetupFlow && authenticated && !shouldShowRequire2FAModal) {
const {adaptedState} = getAdaptedStateFromPath(ROUTES.ONBOARDING_ROOT.route, linkingConfig.config);
return adaptedState;
}
Expand Down
Loading