Skip to content

Commit

Permalink
Merge pull request #38142 from ikevin127/fix/34177
Browse files Browse the repository at this point in the history
Desktop - Login - Unable to enter the 2FA code or exit the screen
  • Loading branch information
mountiny authored Mar 20, 2024
2 parents 99169e1 + 70136ac commit 8f73790
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libs/desktopLoginRedirect/index.desktop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import type {AutoAuthState} from '@src/types/onyx/Session';

function desktopLoginRedirect(autoAuthState: AutoAuthState, isSignedIn: boolean) {
// NOT_STARTED - covers edge case of autoAuthState not being initialized yet (after logout)
// JUST_SIGNED_IN - confirms passing the magic code step -> we're either logged-in or shown 2FA screen
// !isSignedIn - confirms we're not signed-in yet as there's possible one last step (2FA validation)
const shouldPopToTop = (autoAuthState === CONST.AUTO_AUTH_STATE.NOT_STARTED || autoAuthState === CONST.AUTO_AUTH_STATE.JUST_SIGNED_IN) && !isSignedIn;

if (shouldPopToTop) {
Navigation.isNavigationReady().then(() => Navigation.resetToHome());
}
}

export default desktopLoginRedirect;
5 changes: 5 additions & 0 deletions src/libs/desktopLoginRedirect/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type {AutoAuthState} from '@src/types/onyx/Session';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function desktopLoginRedirect(autoAuthState: AutoAuthState, isSignedIn: boolean) {}
export default desktopLoginRedirect;
6 changes: 6 additions & 0 deletions src/pages/ValidateLoginPage/index.website.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import ExpiredValidateCodeModal from '@components/ValidateCode/ExpiredValidateCodeModal';
import JustSignedInModal from '@components/ValidateCode/JustSignedInModal';
import ValidateCodeModal from '@components/ValidateCode/ValidateCodeModal';
import desktopLoginRedirect from '@libs/desktopLoginRedirect';
import Navigation from '@libs/Navigation/Navigation';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -43,6 +44,11 @@ function ValidateLoginPage({

// The user has initiated the sign in process on the same browser, in another tab.
Session.signInWithValidateCode(Number(accountID), validateCode);

// Since on Desktop we don't have multi-tab functionality to handle the login flow,
// we need to `popToTop` the stack after `signInWithValidateCode` in order to
// perform login for both 2FA and non-2FA accounts.
desktopLoginRedirect(autoAuthState, isSignedIn);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down

0 comments on commit 8f73790

Please sign in to comment.