From 4a3d4a600173d96fd346c5ec9e05cb1fd4edb4e7 Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 25 Sep 2023 23:09:41 +0700 Subject: [PATCH 1/3] fix email is not showing in authenticator app for newly created account --- .../TwoFactorAuth/Steps/VerifyStep.js | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.js b/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.js index eb08a8da316b..7783b6c58ace 100644 --- a/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.js +++ b/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.js @@ -1,6 +1,7 @@ import React, {useEffect} from 'react'; import {withOnyx} from 'react-native-onyx'; import {ScrollView, View} from 'react-native'; +import PropTypes from 'prop-types'; import * as Session from '../../../../../libs/actions/Session'; import styles from '../../../../../styles/styles'; import Button from '../../../../../components/Button'; @@ -22,7 +23,14 @@ import {defaultAccount, TwoFactorAuthPropTypes} from '../TwoFactorAuthPropTypes' const TROUBLESHOOTING_LINK = 'https://community.expensify.com/discussion/7736/faq-troubleshooting-two-factor-authentication-issues/p1?new=1'; -function VerifyStep({account = defaultAccount}) { +const defaultProps = { + account: defaultAccount, + session: { + email: null, + }, +}; + +function VerifyStep({account, session}) { const {translate} = useLocalize(); const formRef = React.useRef(null); @@ -61,7 +69,7 @@ function VerifyStep({account = defaultAccount}) { * @returns {string} */ function buildAuthenticatorUrl() { - return `otpauth://totp/Expensify:${account.primaryLogin}?secret=${account.twoFactorAuthSecretKey}&issuer=Expensify`; + return `otpauth://totp/Expensify:${account.primaryLogin || session.email}?secret=${account.twoFactorAuthSecretKey}&issuer=Expensify`; } return ( @@ -128,9 +136,20 @@ function VerifyStep({account = defaultAccount}) { ); } -VerifyStep.propTypes = TwoFactorAuthPropTypes; +VerifyStep.propTypes = { + /** Information about the users account that is logging in */ + account: TwoFactorAuthPropTypes.account, + + /** Session of currently logged in user */ + session: PropTypes.shape({ + /** Email address */ + email: PropTypes.string.isRequired, + }), +}; +VerifyStep.defaultProps = defaultProps; // eslint-disable-next-line rulesdir/onyx-props-must-have-default export default withOnyx({ account: {key: ONYXKEYS.ACCOUNT}, + session: {key: ONYXKEYS.SESSION}, })(VerifyStep); From 38dd2530ff018b680d2462a19113d40b3f5c0b10 Mon Sep 17 00:00:00 2001 From: Hans Date: Sun, 1 Oct 2023 16:08:19 +0700 Subject: [PATCH 2/3] use detructuring --- .../settings/Security/TwoFactorAuth/Steps/VerifyStep.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.js b/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.js index 7783b6c58ace..e94f04245233 100644 --- a/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.js +++ b/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.js @@ -1,3 +1,4 @@ +/* eslint-disable rulesdir/onyx-props-must-have-default */ import React, {useEffect} from 'react'; import {withOnyx} from 'react-native-onyx'; import {ScrollView, View} from 'react-native'; @@ -23,14 +24,13 @@ import {defaultAccount, TwoFactorAuthPropTypes} from '../TwoFactorAuthPropTypes' const TROUBLESHOOTING_LINK = 'https://community.expensify.com/discussion/7736/faq-troubleshooting-two-factor-authentication-issues/p1?new=1'; -const defaultProps = { - account: defaultAccount, +const defaultSession = { session: { email: null, }, }; -function VerifyStep({account, session}) { +function VerifyStep({account = defaultAccount, session = defaultSession}) { const {translate} = useLocalize(); const formRef = React.useRef(null); @@ -146,9 +146,7 @@ VerifyStep.propTypes = { email: PropTypes.string.isRequired, }), }; -VerifyStep.defaultProps = defaultProps; -// eslint-disable-next-line rulesdir/onyx-props-must-have-default export default withOnyx({ account: {key: ONYXKEYS.ACCOUNT}, session: {key: ONYXKEYS.SESSION}, From f20276fc7bc39b7bc39ff700202d0fc1b4bfe925 Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 2 Oct 2023 11:20:37 +0700 Subject: [PATCH 3/3] revert detructuring --- .../settings/Security/TwoFactorAuth/Steps/VerifyStep.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.js b/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.js index e94f04245233..7783b6c58ace 100644 --- a/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.js +++ b/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.js @@ -1,4 +1,3 @@ -/* eslint-disable rulesdir/onyx-props-must-have-default */ import React, {useEffect} from 'react'; import {withOnyx} from 'react-native-onyx'; import {ScrollView, View} from 'react-native'; @@ -24,13 +23,14 @@ import {defaultAccount, TwoFactorAuthPropTypes} from '../TwoFactorAuthPropTypes' const TROUBLESHOOTING_LINK = 'https://community.expensify.com/discussion/7736/faq-troubleshooting-two-factor-authentication-issues/p1?new=1'; -const defaultSession = { +const defaultProps = { + account: defaultAccount, session: { email: null, }, }; -function VerifyStep({account = defaultAccount, session = defaultSession}) { +function VerifyStep({account, session}) { const {translate} = useLocalize(); const formRef = React.useRef(null); @@ -146,7 +146,9 @@ VerifyStep.propTypes = { email: PropTypes.string.isRequired, }), }; +VerifyStep.defaultProps = defaultProps; +// eslint-disable-next-line rulesdir/onyx-props-must-have-default export default withOnyx({ account: {key: ONYXKEYS.ACCOUNT}, session: {key: ONYXKEYS.SESSION},