@@ -4,7 +4,7 @@ import type {OnyxEntry} from 'react-native-onyx';
44import CONFIG from '@src/CONFIG' ;
55import CONST from '@src/CONST' ;
66import ONYXKEYS from '@src/ONYXKEYS' ;
7- import type { Credentials , HybridApp , Session , TryNewDot } from '@src/types/onyx' ;
7+ import type { Account , Credentials , HybridApp , Session , TryNewDot } from '@src/types/onyx' ;
88import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
99import { closeReactNativeApp , setReadyToShowAuthScreens , setUseNewDotSignInPage } from './actions/HybridApp' ;
1010import Log from './Log' ;
@@ -18,36 +18,45 @@ let currentHybridApp: OnyxEntry<HybridApp>;
1818let currentTryNewDot : OnyxEntry < TryNewDot > ;
1919let currentCredentials : OnyxEntry < Credentials > ;
2020let currentSession : OnyxEntry < Session > ;
21+ let currentAccount : OnyxEntry < Account > ;
2122
2223Onyx . connectWithoutView ( {
2324 key : ONYXKEYS . HYBRID_APP ,
2425 callback : ( hybridApp ) => {
2526 currentHybridApp = hybridApp ;
26- signInToOldDotAndChooseExperience ( hybridApp , currentTryNewDot , currentCredentials , currentSession ) ;
27+ signInToOldDotAndChooseExperience ( hybridApp , currentTryNewDot , currentCredentials , currentSession , currentAccount ) ;
2728 } ,
2829} ) ;
2930
3031Onyx . connectWithoutView ( {
3132 key : ONYXKEYS . NVP_TRY_NEW_DOT ,
3233 callback : ( tryNewDot ) => {
3334 currentTryNewDot = tryNewDot ;
34- signInToOldDotAndChooseExperience ( currentHybridApp , tryNewDot , currentCredentials , currentSession ) ;
35+ signInToOldDotAndChooseExperience ( currentHybridApp , tryNewDot , currentCredentials , currentSession , currentAccount ) ;
3536 } ,
3637} ) ;
3738
3839Onyx . connectWithoutView ( {
3940 key : ONYXKEYS . CREDENTIALS ,
4041 callback : ( credentials ) => {
4142 currentCredentials = credentials ;
42- signInToOldDotAndChooseExperience ( currentHybridApp , currentTryNewDot , credentials , currentSession ) ;
43+ signInToOldDotAndChooseExperience ( currentHybridApp , currentTryNewDot , credentials , currentSession , currentAccount ) ;
4344 } ,
4445} ) ;
4546
4647Onyx . connectWithoutView ( {
4748 key : ONYXKEYS . SESSION ,
4849 callback : ( session : OnyxEntry < Session > ) => {
4950 currentSession = session ;
50- signInToOldDotAndChooseExperience ( currentHybridApp , currentTryNewDot , currentCredentials , session ) ;
51+ signInToOldDotAndChooseExperience ( currentHybridApp , currentTryNewDot , currentCredentials , session , currentAccount ) ;
52+ } ,
53+ } ) ;
54+
55+ Onyx . connectWithoutView ( {
56+ key : ONYXKEYS . ACCOUNT ,
57+ callback : ( account : OnyxEntry < Account > ) => {
58+ currentAccount = account ;
59+ signInToOldDotAndChooseExperience ( currentHybridApp , currentTryNewDot , currentCredentials , currentSession , account ) ;
5160 } ,
5261} ) ;
5362
@@ -70,7 +79,13 @@ function shouldUseOldApp(tryNewDot: TryNewDot) {
7079 * Signs the user into OldDot when session and credentials are available,
7180 * then decides whether to stay in NewDot or switch to OldDot based on `nvp_tryNewDot`.
7281 */
73- function signInToOldDotAndChooseExperience ( hybridApp : OnyxEntry < HybridApp > , tryNewDot : OnyxEntry < TryNewDot > , credentials : OnyxEntry < Credentials > , session : OnyxEntry < Session > ) {
82+ function signInToOldDotAndChooseExperience (
83+ hybridApp : OnyxEntry < HybridApp > ,
84+ tryNewDot : OnyxEntry < TryNewDot > ,
85+ credentials : OnyxEntry < Credentials > ,
86+ session : OnyxEntry < Session > ,
87+ account : OnyxEntry < Account > ,
88+ ) {
7489 if ( ! CONFIG . IS_HYBRID_APP ) {
7590 return ;
7691 }
@@ -84,7 +99,7 @@ function signInToOldDotAndChooseExperience(hybridApp: OnyxEntry<HybridApp>, tryN
8499 return ;
85100 }
86101
87- if ( ! credentials ?. autoGeneratedLogin || ! credentials ?. autoGeneratedPassword ) {
102+ if ( ! credentials ?. autoGeneratedLogin || ! credentials ?. autoGeneratedPassword || account ?. requiresTwoFactorAuth === undefined || account ?. needsTwoFactorAuthSetup === undefined ) {
88103 return ;
89104 }
90105
@@ -106,7 +121,7 @@ function signInToOldDotAndChooseExperience(hybridApp: OnyxEntry<HybridApp>, tryN
106121
107122 if ( tryNewDot !== undefined ) {
108123 setUseNewDotSignInPage ( false ) . then ( ( ) => {
109- if ( shouldUseOldApp ( tryNewDot ) ) {
124+ if ( shouldUseOldApp ( tryNewDot ) && ( ! account ?. needsTwoFactorAuthSetup || account ?. requiresTwoFactorAuth ) ) {
110125 closeReactNativeApp ( { shouldSetNVP : false , isTrackingGPS : false } ) ;
111126 } else {
112127 setReadyToShowAuthScreens ( true ) ;
0 commit comments