Skip to content

Commit

Permalink
Merge pull request #15709 from Expensify/cristi_avoid-sending-account…
Browse files Browse the repository at this point in the history
…ID-in-SIgninUser-command

Remove accountID param when signing with SigninUser command
  • Loading branch information
NikkiWines authored Mar 11, 2023
2 parents b69b5f3 + 271ac44 commit 71ffd42
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
17 changes: 5 additions & 12 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,7 @@ function signIn(password, validateCode, twoFactorAuthCode) {
},
];

const params = {twoFactorAuthCode};
if (credentials.login) {
// The user initiated the sign in operation on the current device, sign in with the email
params.email = credentials.login;
} else {
// The user is signing in with the accountID and validateCode from the magic link
params.accountID = credentials.accountID;
}
const params = {twoFactorAuthCode, email: credentials.login};

// Conditionally pass a password or validateCode to command since we temporarily allow both flows
if (validateCode) {
Expand All @@ -296,7 +289,7 @@ function signIn(password, validateCode, twoFactorAuthCode) {
API.write('SigninUser', params, {optimisticData, successData, failureData});
}

function signInWithValidateCode(accountID, validateCode) {
function signInWithValidateCode(accountID, validateCode, twoFactorAuthCode) {
const optimisticData = [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
Expand Down Expand Up @@ -336,10 +329,10 @@ function signInWithValidateCode(accountID, validateCode) {
},
];

// This is temporary for now. Server should login with the accountID and validateCode
API.write('SigninUser', {
validateCode,
API.write('SigninUserWithLink', {
accountID,
validateCode,
twoFactorAuthCode,
}, {optimisticData, successData, failureData});
}

Expand Down
18 changes: 5 additions & 13 deletions src/pages/ValidateLoginPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,21 @@ const defaultProps = {

class ValidateLoginPage extends Component {
componentDidMount() {
const accountID = lodashGet(this.props.route.params, 'accountID', '');
const validateCode = lodashGet(this.props.route.params, 'validateCode', '');
if (Permissions.canUsePasswordlessLogins(this.props.betas)) {
if (lodashGet(this.props, 'session.authToken', null)) {
if (lodashGet(this.props, 'session.authToken')) {
// If already signed in, do not show the validate code if not on web,
// because we don't want to block the user with the interstitial page.
Navigation.goBack(false);
} else {
Session.signInWithValidateCodeAndNavigate(this.accountID(), this.validateCode());
Session.signInWithValidateCodeAndNavigate(accountID, validateCode);
}
} else {
User.validateLogin(this.accountID(), this.validateCode());
User.validateLogin(accountID, validateCode);
}
}

/**
* @returns {String}
*/
accountID = () => lodashGet(this.props.route.params, 'accountID', '');

/**
* @returns {String}
*/
validateCode = () => lodashGet(this.props.route.params, 'validateCode', '');

render() {
return <FullScreenLoadingIndicator />;
}
Expand Down
8 changes: 7 additions & 1 deletion src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import styles from '../../../styles/styles';
import Button from '../../../components/Button';
import Text from '../../../components/Text';
Expand Down Expand Up @@ -175,7 +176,12 @@ class BaseValidateCodeForm extends React.Component {
formError: {},
});

Session.signIn('', this.state.validateCode, this.state.twoFactorAuthCode);
const accountID = lodashGet(this.props, 'credentials.accountID');
if (accountID) {
Session.signInWithValidateCode(accountID, this.state.validateCode, this.state.twoFactorAuthCode);
} else {
Session.signIn('', this.state.validateCode, this.state.twoFactorAuthCode);
}
}

render() {
Expand Down

0 comments on commit 71ffd42

Please sign in to comment.