Skip to content

Commit

Permalink
Merge pull request #18854 from Prince-Mendiratta/fix/18505-2fa-valida…
Browse files Browse the repository at this point in the history
…tion-on-refresh

[2FA] fix: Submit 2FA code after refresh
  • Loading branch information
tgolen authored May 15, 2023
2 parents a930756 + 80208fe commit 5743b15
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
11 changes: 9 additions & 2 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = CON
isLoading: false,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.CREDENTIALS,
value: {
validateCode,
},
},
];

const failureData = [
Expand All @@ -367,8 +374,8 @@ function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = CON
};

// Conditionally pass a password or validateCode to command since we temporarily allow both flows
if (validateCode) {
params.validateCode = validateCode;
if (validateCode || twoFactorAuthCode) {
params.validateCode = validateCode || credentials.validateCode;
} else {
params.password = password;
}
Expand Down
35 changes: 18 additions & 17 deletions src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,25 @@ class BaseValidateCodeForm extends React.Component {
validateAndSubmitForm() {
const requiresTwoFactorAuth = this.props.account.requiresTwoFactorAuth;

if (!this.state.validateCode.trim()) {
this.setState({formError: {validateCode: 'validateCodeForm.error.pleaseFillMagicCode'}});
return;
}

if (!ValidationUtils.isValidValidateCode(this.state.validateCode)) {
this.setState({formError: {validateCode: 'validateCodeForm.error.incorrectMagicCode'}});
return;
}
if (requiresTwoFactorAuth) {
if (!this.state.twoFactorAuthCode.trim()) {
this.setState({formError: {twoFactorAuthCode: 'validateCodeForm.error.pleaseFillTwoFactorAuth'}});
return;
}

if (requiresTwoFactorAuth && !this.state.twoFactorAuthCode.trim()) {
this.setState({formError: {twoFactorAuthCode: 'validateCodeForm.error.pleaseFillTwoFactorAuth'}});
return;
}

if (requiresTwoFactorAuth && !ValidationUtils.isValidTwoFactorCode(this.state.twoFactorAuthCode)) {
this.setState({formError: {twoFactorAuthCode: 'passwordForm.error.incorrect2fa'}});
return;
if (!ValidationUtils.isValidTwoFactorCode(this.state.twoFactorAuthCode)) {
this.setState({formError: {twoFactorAuthCode: 'passwordForm.error.incorrect2fa'}});
return;
}
} else {
if (!this.state.validateCode.trim()) {
this.setState({formError: {validateCode: 'validateCodeForm.error.pleaseFillMagicCode'}});
return;
}
if (!ValidationUtils.isValidValidateCode(this.state.validateCode)) {
this.setState({formError: {validateCode: 'validateCodeForm.error.incorrectMagicCode'}});
return;
}
}

this.setState({
Expand Down

0 comments on commit 5743b15

Please sign in to comment.