Skip to content

Commit 818bf17

Browse files
authored
Merge pull request Expensify#81984 from software-mansion-labs/war-in/fix-require-2fa-domain
fix: keep user in ND until they setup 2FA when required
2 parents 205a330 + 4480a7e commit 818bf17

2 files changed

Lines changed: 42 additions & 8 deletions

File tree

src/libs/HybridApp.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {OnyxEntry} from 'react-native-onyx';
44
import CONFIG from '@src/CONFIG';
55
import CONST from '@src/CONST';
66
import 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';
88
import {isEmptyObject} from '@src/types/utils/EmptyObject';
99
import {closeReactNativeApp, setReadyToShowAuthScreens, setUseNewDotSignInPage} from './actions/HybridApp';
1010
import Log from './Log';
@@ -18,36 +18,45 @@ let currentHybridApp: OnyxEntry<HybridApp>;
1818
let currentTryNewDot: OnyxEntry<TryNewDot>;
1919
let currentCredentials: OnyxEntry<Credentials>;
2020
let currentSession: OnyxEntry<Session>;
21+
let currentAccount: OnyxEntry<Account>;
2122

2223
Onyx.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

3031
Onyx.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

3839
Onyx.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

4647
Onyx.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);

src/pages/settings/Security/TwoFactorAuth/SuccessPage.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
import React, {useCallback, useEffect} from 'react';
2+
import type {OnyxEntry} from 'react-native-onyx';
23
import ConfirmationPage from '@components/ConfirmationPage';
34
import LottieAnimations from '@components/LottieAnimations';
45
import useEnvironment from '@hooks/useEnvironment';
56
import useLocalize from '@hooks/useLocalize';
7+
import useOnyx from '@hooks/useOnyx';
68
import useThemeStyles from '@hooks/useThemeStyles';
79
import Navigation from '@libs/Navigation/Navigation';
810
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
911
import type {TwoFactorAuthNavigatorParamList} from '@libs/Navigation/types';
12+
import {closeReactNativeApp} from '@userActions/HybridApp';
1013
import {openLink} from '@userActions/Link';
1114
import {quitAndNavigateBack} from '@userActions/TwoFactorAuthActions';
15+
import CONFIG from '@src/CONFIG';
1216
import CONST from '@src/CONST';
17+
import ONYXKEYS from '@src/ONYXKEYS';
1318
import ROUTES from '@src/ROUTES';
1419
import type SCREENS from '@src/SCREENS';
20+
import type {TryNewDot} from '@src/types/onyx';
1521
import TwoFactorAuthWrapper from './TwoFactorAuthWrapper';
1622

1723
type SuccessPageProps = PlatformStackScreenProps<TwoFactorAuthNavigatorParamList, typeof SCREENS.TWO_FACTOR_AUTH.SUCCESS>;
1824

25+
function classicRedirectDismissedSelector(tryNewDot: OnyxEntry<TryNewDot>) {
26+
return tryNewDot?.classicRedirect?.dismissed;
27+
}
28+
1929
function SuccessPage({route}: SuccessPageProps) {
2030
const {translate} = useLocalize();
2131
const {environmentURL} = useEnvironment();
2232
const styles = useThemeStyles();
2333

34+
const [isClassicRedirectDismissed] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, {
35+
selector: classicRedirectDismissedSelector,
36+
canBeMissing: true,
37+
});
38+
2439
const goBack = useCallback(() => {
2540
quitAndNavigateBack(route.params?.backTo ?? ROUTES.SETTINGS_2FA_ROOT.getRoute());
2641
}, [route.params?.backTo]);
@@ -49,6 +64,10 @@ function SuccessPage({route}: SuccessPageProps) {
4964
shouldShowButton
5065
buttonText={translate('common.buttonConfirm')}
5166
onButtonPress={() => {
67+
if (CONFIG.IS_HYBRID_APP && isClassicRedirectDismissed) {
68+
closeReactNativeApp({shouldSetNVP: false, isTrackingGPS: false});
69+
return;
70+
}
5271
goBack();
5372
if (route.params?.forwardTo) {
5473
openLink(route.params.forwardTo, environmentURL);

0 commit comments

Comments
 (0)