Skip to content

Commit

Permalink
feat: save magic code in onyx
Browse files Browse the repository at this point in the history
Signed-off-by: Prince Mendiratta <[email protected]>
  • Loading branch information
Prince-Mendiratta committed May 12, 2023
1 parent 3906d18 commit 80208fe
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 @@ -335,6 +335,13 @@ function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = CON
isLoading: false,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.CREDENTIALS,
value: {
validateCode,
},
},
];

const failureData = [
Expand All @@ -350,8 +357,8 @@ function signIn(password, validateCode, twoFactorAuthCode, preferredLocale = CON
const params = {twoFactorAuthCode, email: credentials.login, preferredLocale};

// 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 80208fe

Please sign in to comment.