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 bug where 2FA input field is permanently hidden after resetting password #8801

Merged
merged 8 commits into from
Apr 29, 2022
22 changes: 16 additions & 6 deletions src/pages/signin/PasswordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class PasswordForm extends React.Component {
constructor(props) {
super(props);
this.validateAndSubmitForm = this.validateAndSubmitForm.bind(this);
this.resetPassword = this.resetPassword.bind(this);

this.state = {
formError: false,
Expand All @@ -56,15 +57,15 @@ class PasswordForm extends React.Component {
}

componentDidMount() {
if (!canFocusInputOnScreenFocus() || !this.input || !this.props.isVisible) {
if (!canFocusInputOnScreenFocus() || !this.inputPassword || !this.props.isVisible) {
return;
}
this.input.focus();
this.inputPassword.focus();
}

componentDidUpdate(prevProps) {
if (!prevProps.isVisible && this.props.isVisible) {
this.input.focus();
this.inputPassword.focus();
}
if (prevProps.isVisible && !this.props.isVisible && this.state.password) {
this.clearPassword();
Expand All @@ -75,7 +76,15 @@ class PasswordForm extends React.Component {
* Clear Password from the state
*/
clearPassword() {
this.setState({password: ''}, this.input.clear);
this.setState({password: ''}, this.inputPassword.clear);
}

/**
* Trigger the reset password flow and ensure the 2FA input field is reset to avoid it being permanently hidden
*/
resetPassword() {
this.setState({twoFactorAuthCode: ''}, this.input2FA.clear);
Session.resetPassword();
}

/**
Expand Down Expand Up @@ -109,7 +118,7 @@ class PasswordForm extends React.Component {
<>
<View style={[styles.mv3]}>
<TextInput
ref={el => this.input = el}
ref={el => this.inputPassword = el}
label={this.props.translate('common.password')}
secureTextEntry
autoCompleteType={ComponentUtils.PASSWORD_AUTOCOMPLETE_TYPE}
Expand All @@ -124,7 +133,7 @@ class PasswordForm extends React.Component {
<View style={[styles.changeExpensifyLoginLinkContainer]}>
<TouchableOpacity
style={[styles.mt2]}
onPress={Session.resetPassword}
onPress={this.resetPassword}
underlayColor={themeColors.componentBG}
>
<Text style={[styles.link]}>
Expand All @@ -137,6 +146,7 @@ class PasswordForm extends React.Component {
{this.props.account.requiresTwoFactorAuth && (
<View style={[styles.mv3]}>
<TextInput
ref={el => this.input2FA = el}
label={this.props.translate('passwordForm.twoFactorCode')}
value={this.state.twoFactorAuthCode}
placeholder={this.props.translate('passwordForm.requiredWhen2FAEnabled')}
Expand Down