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: 2FA bug fixes #19260

Merged
merged 17 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! Is this file really needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

I just merged main and installed dependencies. I guess in some other PR the dependencies were updated but the lockfile wasn't pushed

Original file line number Diff line number Diff line change
Expand Up @@ -1135,4 +1135,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 4ed1c7b099741c82e2b0411b95f6468e72be6c76

COCOAPODS: 1.12.1
COCOAPODS: 1.12.0
5 changes: 5 additions & 0 deletions src/components/withWindowDimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const windowDimensionsPropTypes = {
// Height of the window
windowHeight: PropTypes.number.isRequired,

// Is the window width extra narrow, like on a Fold mobile device?
isExtraSmallScreenWidth: PropTypes.bool.isRequired,

// Is the window width narrow, like on a mobile device?
isSmallScreenWidth: PropTypes.bool.isRequired,

Expand Down Expand Up @@ -75,6 +78,7 @@ class WindowDimensionsProvider extends React.Component {
return (
<SafeAreaInsetsContext.Consumer>
{(insets) => {
const isExtraSmallScreenWidth = this.state.windowWidth <= variables.extraSmallMobileResponsiveWidthBreakpoint;
const isSmallScreenWidth = this.state.windowWidth <= variables.mobileResponsiveWidthBreakpoint;
const isMediumScreenWidth = !isSmallScreenWidth && this.state.windowWidth <= variables.tabletResponsiveWidthBreakpoint;
const isLargeScreenWidth = !isSmallScreenWidth && !isMediumScreenWidth;
Expand All @@ -83,6 +87,7 @@ class WindowDimensionsProvider extends React.Component {
value={{
windowHeight: this.state.windowHeight + getWindowHeightAdjustment(insets),
windowWidth: this.state.windowWidth,
isExtraSmallScreenWidth,
isSmallScreenWidth,
isMediumScreenWidth,
isLargeScreenWidth,
Expand Down
18 changes: 9 additions & 9 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
zoom: 'Zoom',
password: 'Password',
magicCode: 'Magic code',
twoFactorCode: 'Two factor code',
twoFactorCode: 'Two-factor code',
workspaces: 'Workspaces',
profile: 'Profile',
payments: 'Payments',
Expand Down Expand Up @@ -195,7 +195,7 @@ export default {
requestNewCode: 'You can also',
requestNewCodeLink: 'request a new code here',
successfulNewCodeRequest: 'Code requested. Please check your device.',
tfaRequiredTitle: 'Two factor authentication\nrequired',
tfaRequiredTitle: 'Two-factor authentication\nrequired',
tfaRequiredDescription: 'Please enter the two-factor authentication code\nwhere you are trying to sign in.',
},
moneyRequestConfirmationList: {
Expand Down Expand Up @@ -533,7 +533,7 @@ export default {
stepCodes: 'Recovery codes',
keepCodesSafe: 'Keep these recovery codes safe!',
codesLoseAccess:
'If you lose access to your authenticator app and don’t have these codes, you will lose access to your account. \n\nNote: Setting up two factor authentication will log you out of all other active sessions.',
'If you lose access to your authenticator app and don’t have these codes, you will lose access to your account. \n\nNote: Setting up two-factor authentication will log you out of all other active sessions.',
stepVerify: 'Verify',
scanCode: 'Scan the QR code using your',
authenticatorApp: 'authenticator app',
Expand All @@ -548,8 +548,8 @@ export default {
},
twoFactorAuthForm: {
error: {
pleaseFillTwoFactorAuth: 'Please enter your two factor code',
incorrect2fa: 'Incorrect two factor authentication code. Please try again.',
pleaseFillTwoFactorAuth: 'Please enter your two-factor code',
incorrect2fa: 'Incorrect two-factor authentication code. Please try again.',
},
},
passwordConfirmationScreen: {
Expand Down Expand Up @@ -692,20 +692,20 @@ export default {
error: {
pleaseFillMagicCode: 'Please enter your magic code',
incorrectMagicCode: 'Incorrect magic code.',
pleaseFillTwoFactorAuth: 'Please enter your two factor code',
pleaseFillTwoFactorAuth: 'Please enter your two-factor code',
},
},
passwordForm: {
pleaseFillOutAllFields: 'Please fill out all fields',
pleaseFillPassword: 'Please enter your password',
pleaseFillTwoFactorAuth: 'Please enter your two factor code',
enterYourTwoFactorAuthenticationCodeToContinue: 'Enter your two factor authentication code to continue',
pleaseFillTwoFactorAuth: 'Please enter your two-factor code',
enterYourTwoFactorAuthenticationCodeToContinue: 'Enter your two-factor authentication code to continue',
forgot: 'Forgot?',
requiredWhen2FAEnabled: 'Required when 2FA is enabled',
error: {
incorrectPassword: 'Incorrect password. Please try again.',
incorrectLoginOrPassword: 'Incorrect login or password. Please try again.',
incorrect2fa: 'Incorrect two factor authentication code. Please try again.',
incorrect2fa: 'Incorrect two-factor authentication code. Please try again.',
twoFactorAuthenticationEnabled: 'You have 2FA enabled on this account. Please sign in using your email or phone number.',
invalidLoginOrPassword: 'Invalid login or password. Please try again or reset your password.',
unableToResetPassword:
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReimbursementAccount/ValidationStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const propTypes = {

/** User's account who is setting up bank account */
account: PropTypes.shape({
/** If user has Two factor authentication enabled */
/** If user has two-factor authentication enabled */
requiresTwoFactorAuth: PropTypes.bool,
}),
};
Expand Down
13 changes: 7 additions & 6 deletions src/pages/ValidateLoginPage/index.website.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,21 @@ class ValidateLoginPage extends Component {
}

render() {
const isTfaRequired = lodashGet(this.props, 'account.requiresTwoFactorAuth', false);
const is2FARequired = lodashGet(this.props, 'account.requiresTwoFactorAuth', false);
const isSignedIn = Boolean(lodashGet(this.props, 'session.authToken', null));
const currentAuthState = this.getAutoAuthState();
return (
<>
{this.getAutoAuthState() === CONST.AUTO_AUTH_STATE.FAILED && <ExpiredValidateCodeModal />}
{this.getAutoAuthState() === CONST.AUTO_AUTH_STATE.JUST_SIGNED_IN && (!isTfaRequired || isSignedIn) && <AbracadabraModal />}
{this.getAutoAuthState() === CONST.AUTO_AUTH_STATE.JUST_SIGNED_IN && isTfaRequired && !isSignedIn && <TfaRequiredModal />}
{this.getAutoAuthState() === CONST.AUTO_AUTH_STATE.NOT_STARTED && (
{currentAuthState === CONST.AUTO_AUTH_STATE.FAILED && <ExpiredValidateCodeModal />}
{currentAuthState === CONST.AUTO_AUTH_STATE.JUST_SIGNED_IN && is2FARequired && !isSignedIn && <TfaRequiredModal />}
{currentAuthState === CONST.AUTO_AUTH_STATE.NOT_STARTED && isSignedIn && <AbracadabraModal />}
{currentAuthState === CONST.AUTO_AUTH_STATE.NOT_STARTED && !isSignedIn && (
Copy link
Contributor

Choose a reason for hiding this comment

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

@BeeMargarida Do you remember why we had to add the !isSignedIn condition here? This caused a regression #21258

Copy link
Contributor Author

@BeeMargarida BeeMargarida Jun 26, 2023

Choose a reason for hiding this comment

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

@s77rt Yes, it came from this commit to fix this bug mentioned in this slack thread.

Before, it was necessary because the check for AbracadabraModal (now JustSignedInModal) used NOT_STARTED state (this is because the state was cleaned on startup - mentioned in the proposal), so we needed to differentiate between that one and the one for ValidateCodeModal. At the time, the only difference was that for the abracadabra, the isSignedIn was true and false for the ValidateCodeModal.
I don't think it was a regression from here specifically, since this changed a lot after this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@BeeMargarida Thank you!

<ValidateCodeModal
accountID={this.getAccountID()}
code={this.getValidateCode()}
/>
)}
{this.getAutoAuthState() === CONST.AUTO_AUTH_STATE.SIGNING_IN && <FullScreenLoadingIndicator />}
{currentAuthState === CONST.AUTO_AUTH_STATE.SIGNING_IN && <FullScreenLoadingIndicator />}
</>
);
}
Expand Down
122 changes: 64 additions & 58 deletions src/pages/settings/Security/TwoFactorAuth/CodesPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useEffect, useState} from 'react';
import {withOnyx} from 'react-native-onyx';
import {ActivityIndicator, View} from 'react-native';
import {ScrollView} from 'react-native-gesture-handler';
import _ from 'underscore';
import PropTypes from 'prop-types';
import HeaderWithCloseButton from '../../../../components/HeaderWithCloseButton';
Expand All @@ -11,6 +12,7 @@ import compose from '../../../../libs/compose';
import ROUTES from '../../../../ROUTES';
import FullPageOfflineBlockingView from '../../../../components/BlockingViews/FullPageOfflineBlockingView';
import * as Illustrations from '../../../../components/Icon/Illustrations';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../../components/withWindowDimensions';
import styles from '../../../../styles/styles';
import FixedFooter from '../../../../components/FixedFooter';
import Button from '../../../../components/Button';
Expand All @@ -24,6 +26,7 @@ import * as TwoFactorAuthActions from '../../../../libs/actions/TwoFactorAuthAct

const propTypes = {
...withLocalizePropTypes,
...windowDimensionsPropTypes,
account: PropTypes.shape({
/** User recovery codes for setting up 2-FA */
recoveryCodes: PropTypes.string,
Expand Down Expand Up @@ -64,65 +67,67 @@ function CodesPage(props) {
onCloseButtonPress={() => Navigation.dismissModal(true)}
/>
<FullPageOfflineBlockingView>
<Section
title={props.translate('twoFactorAuth.keepCodesSafe')}
icon={Illustrations.ShieldYellow}
containerStyles={[styles.twoFactorAuthSection]}
iconContainerStyles={[styles.ml6]}
>
<View style={styles.mv3}>
<Text>{props.translate('twoFactorAuth.codesLoseAccess')}</Text>
</View>
<View style={styles.twoFactorAuthCodesBox}>
{props.account.isLoading ? (
<View style={styles.twoFactorLoadingContainer}>
<ActivityIndicator color={themeColors.spinner} />
</View>
) : (
<>
<View style={styles.twoFactorAuthCodesContainer}>
{Boolean(props.account.recoveryCodes) &&
_.map(props.account.recoveryCodes.split(', '), (code) => (
<Text
style={styles.twoFactorAuthCode}
key={code}
>
{code}
</Text>
))}
<ScrollView contentContainerStyle={styles.flex1}>
<Section
title={props.translate('twoFactorAuth.keepCodesSafe')}
icon={Illustrations.ShieldYellow}
containerStyles={[styles.twoFactorAuthSection]}
iconContainerStyles={[styles.ml6]}
>
<View style={styles.mv3}>
<Text>{props.translate('twoFactorAuth.codesLoseAccess')}</Text>
</View>
<View style={[styles.twoFactorAuthCodesBox(props)]}>
{props.account.isLoading ? (
<View style={styles.twoFactorLoadingContainer}>
<ActivityIndicator color={themeColors.spinner} />
</View>
<View style={styles.twoFactorAuthCodesButtonsContainer}>
<Button
text={props.translate('twoFactorAuth.copyCodes')}
medium
onPress={() => {
Clipboard.setString(props.account.recoveryCodes);
setIsNextButtonDisabled(false);
}}
style={styles.twoFactorAuthCodesButton}
/>
<Button
text="Download"
medium
onPress={() => {
localFileDownload('two-factor-auth-codes', props.account.recoveryCodes);
setIsNextButtonDisabled(false);
}}
style={styles.twoFactorAuthCodesButton}
/>
</View>
</>
)}
</View>
</Section>
<FixedFooter style={[styles.twoFactorAuthFooter]}>
<Button
success
text={props.translate('common.next')}
onPress={() => Navigation.navigate(ROUTES.SETTINGS_2FA_VERIFY)}
isDisabled={isNextButtonDisabled}
/>
</FixedFooter>
) : (
<>
<View style={styles.twoFactorAuthCodesContainer}>
{Boolean(props.account.recoveryCodes) &&
_.map(props.account.recoveryCodes.split(', '), (code) => (
<Text
style={styles.twoFactorAuthCode}
key={code}
>
{code}
</Text>
))}
</View>
<View style={styles.twoFactorAuthCodesButtonsContainer}>
<Button
text={props.translate('twoFactorAuth.copyCodes')}
medium
onPress={() => {
Clipboard.setString(props.account.recoveryCodes);
setIsNextButtonDisabled(false);
}}
style={styles.twoFactorAuthCodesButton}
/>
<Button
text={props.translate('common.download')}
medium
onPress={() => {
localFileDownload('two-factor-auth-codes', props.account.recoveryCodes);
setIsNextButtonDisabled(false);
}}
style={styles.twoFactorAuthCodesButton}
/>
</View>
</>
)}
</View>
</Section>
<FixedFooter style={[styles.twoFactorAuthFooter]}>
<Button
success
text={props.translate('common.next')}
onPress={() => Navigation.navigate(ROUTES.SETTINGS_2FA_VERIFY)}
isDisabled={isNextButtonDisabled}
/>
</FixedFooter>
Comment on lines +122 to +129
Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel Jun 28, 2023

Choose a reason for hiding this comment

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

Seems we accidentally included FixedFooter inside scroll containers and that led to this regression #20138

</ScrollView>
</FullPageOfflineBlockingView>
</ScreenWrapper>
);
Expand All @@ -133,6 +138,7 @@ CodesPage.defaultProps = defaultProps;

export default compose(
withLocalize,
withWindowDimensions,
withOnyx({
account: {key: ONYXKEYS.ACCOUNT},
}),
Expand Down
5 changes: 5 additions & 0 deletions src/pages/settings/Security/TwoFactorAuth/VerifyPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Navigation from '../../../../libs/Navigation/Navigation';
import ScreenWrapper from '../../../../components/ScreenWrapper';
import withLocalize, {withLocalizePropTypes} from '../../../../components/withLocalize';
import compose from '../../../../libs/compose';
import * as Session from '../../../../libs/actions/Session';
import ROUTES from '../../../../ROUTES';
import FullPageOfflineBlockingView from '../../../../components/BlockingViews/FullPageOfflineBlockingView';
import styles from '../../../../styles/styles';
Expand Down Expand Up @@ -51,6 +52,10 @@ const defaultProps = {
};

function VerifyPage(props) {
useEffect(() => {
Session.clearAccountMessages();
}, []);

useEffect(() => {
if (!props.account.requiresTwoFactorAuth) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/signin/PasswordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const propTypes = {

/** The details about the account that the user is signing in with */
account: PropTypes.shape({
/** Whether or not two factor authentication is required */
/** Whether or not two-factor authentication is required */
requiresTwoFactorAuth: PropTypes.bool,

/** Whether or not a sign on form is loading (being submitted) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const propTypes = {

/** The details about the account that the user is signing in with */
account: PropTypes.shape({
/** Whether or not two factor authentication is required */
/** Whether or not two-factor authentication is required */
requiresTwoFactorAuth: PropTypes.bool,

/** Whether or not a sign on form is loading (being submitted) */
Expand Down
28 changes: 20 additions & 8 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2127,14 +2127,26 @@ const styles = {
padding: 0,
},

twoFactorAuthCodesBox: {
alignItems: 'center',
justifyContent: 'center',
backgroundColor: themeColors.highlightBG,
paddingVertical: 28,
paddingHorizontal: 60,
borderRadius: 16,
marginTop: 32,
twoFactorAuthCodesBox: ({isExtraSmallScreenWidth, isSmallScreenWidth}) => {
let paddingHorizontal = styles.ph15;
Copy link
Contributor

Choose a reason for hiding this comment

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

@shawnborton buddy check please for these new style

Copy link
Contributor

Choose a reason for hiding this comment

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

What exactly am I reviewing here? Just the screenshots from the first comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, Nothing has changed much in the view. I wanted to get an eye on padding prooerty we added to support view for extra small devices.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah got it. Can you show me screenshots of what this looks like in practice please? Thanks!

Copy link
Contributor

@thiagobrez thiagobrez Jun 2, 2023

Choose a reason for hiding this comment

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

@shawnborton Here you go:

Desktop, using padding from Figma: `styles.ph15`
Small screen width (<= 800px), decreased padding until it doesn't break: `styles.ph10`
Extra small screen width (<= 320px), decreased padding until it doesn't break: `styles.ph4`

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay cool, that works for me!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks shawn!


if (isSmallScreenWidth) {
paddingHorizontal = styles.ph10;
}

if (isExtraSmallScreenWidth) {
paddingHorizontal = styles.ph4;
}

return {
alignItems: 'center',
justifyContent: 'center',
backgroundColor: themeColors.highlightBG,
paddingVertical: 28,
borderRadius: 16,
marginTop: 32,
...paddingHorizontal,
};
},

twoFactorLoadingContainer: {
Expand Down
4 changes: 4 additions & 0 deletions src/styles/utilities/spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ export default {
paddingHorizontal: 40,
},

ph15: {
paddingHorizontal: 60,
},

ph25: {
paddingHorizontal: 100,
},
Expand Down
1 change: 1 addition & 0 deletions src/styles/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default {
emojiSize: 20,
emojiLineHeight: 28,
iouAmountTextSize: 40,
extraSmallMobileResponsiveWidthBreakpoint: 320,
mobileResponsiveWidthBreakpoint: 800,
modalFullscreenBackdropOpacity: 0.5,
tabletResponsiveWidthBreakpoint: 1024,
Expand Down
Loading