Skip to content

Commit

Permalink
Merge pull request #26948 from hoangzinh/df/26133
Browse files Browse the repository at this point in the history
Fix Sign in- Language preference doesn't persist when user Signs in with google
  • Loading branch information
bondydaa authored Sep 26, 2023
2 parents 0b2c950 + 2f667fe commit 3e9fdf6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/components/ValidateCode/ValidateCodeModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const defaultProps = {
};

function ValidateCodeModal(props) {
const signInHere = useCallback(() => Session.signInWithValidateCode(props.accountID, props.code, props.preferredLocale), [props.accountID, props.code, props.preferredLocale]);
const signInHere = useCallback(() => Session.signInWithValidateCode(props.accountID, props.code), [props.accountID, props.code]);

return (
<View style={styles.deeplinkWrapperContainer}>
Expand Down
19 changes: 12 additions & 7 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Onyx.connect({
callback: (val) => (credentials = val || {}),
});

let preferredLocale;
Onyx.connect({
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
callback: (val) => (preferredLocale = val),
});

/**
* Clears the Onyx store and redirects user to the sign in page
*/
Expand Down Expand Up @@ -254,7 +260,7 @@ function beginSignIn(login) {
*/
function beginAppleSignIn(idToken) {
const {optimisticData, successData, failureData} = signInAttemptState();
API.write('SignInWithApple', {idToken}, {optimisticData, successData, failureData});
API.write('SignInWithApple', {idToken, preferredLocale}, {optimisticData, successData, failureData});
}

/**
Expand All @@ -265,7 +271,7 @@ function beginAppleSignIn(idToken) {
*/
function beginGoogleSignIn(token) {
const {optimisticData, successData, failureData} = signInAttemptState();
API.write('SignInWithGoogle', {token}, {optimisticData, successData, failureData});
API.write('SignInWithGoogle', {token, preferredLocale}, {optimisticData, successData, failureData});
}

/**
Expand Down Expand Up @@ -321,9 +327,8 @@ function signInWithShortLivedAuthToken(email, authToken) {
*
* @param {String} validateCode 6 digit code required for login
* @param {String} [twoFactorAuthCode]
* @param {String} [preferredLocale] Indicates which language to use when the user lands in the app
*/
function signIn(validateCode, twoFactorAuthCode, preferredLocale = CONST.LOCALES.DEFAULT) {
function signIn(validateCode, twoFactorAuthCode) {
const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -380,7 +385,7 @@ function signIn(validateCode, twoFactorAuthCode, preferredLocale = CONST.LOCALES
});
}

function signInWithValidateCode(accountID, code, preferredLocale = CONST.LOCALES.DEFAULT, twoFactorAuthCode = '') {
function signInWithValidateCode(accountID, code, twoFactorAuthCode = '') {
// If this is called from the 2fa step, get the validateCode directly from onyx
// instead of the one passed from the component state because the state is changing when this method is called.
const validateCode = twoFactorAuthCode ? credentials.validateCode : code;
Expand Down Expand Up @@ -456,8 +461,8 @@ function signInWithValidateCode(accountID, code, preferredLocale = CONST.LOCALES
});
}

function signInWithValidateCodeAndNavigate(accountID, validateCode, preferredLocale = CONST.LOCALES.DEFAULT, twoFactorAuthCode = '') {
signInWithValidateCode(accountID, validateCode, preferredLocale, twoFactorAuthCode);
function signInWithValidateCodeAndNavigate(accountID, validateCode, twoFactorAuthCode = '') {
signInWithValidateCode(accountID, validateCode, twoFactorAuthCode);
Navigation.navigate(ROUTES.HOME);
}

Expand Down
5 changes: 1 addition & 4 deletions src/pages/ValidateLoginPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {propTypes as validateLinkPropTypes, defaultProps as validateLinkDefaultP
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';
import ONYXKEYS from '../../ONYXKEYS';
import * as Session from '../../libs/actions/Session';
import useLocalize from '../../hooks/useLocalize';
import Navigation from '../../libs/Navigation/Navigation';

const propTypes = {
Expand Down Expand Up @@ -35,8 +34,6 @@ const defaultProps = {
};

function ValidateLoginPage(props) {
const {preferredLocale} = useLocalize();

useEffect(() => {
const accountID = lodashGet(props.route.params, 'accountID', '');
const validateCode = lodashGet(props.route.params, 'validateCode', '');
Expand All @@ -46,7 +43,7 @@ function ValidateLoginPage(props) {
// because we don't want to block the user with the interstitial page.
Navigation.goBack(false);
} else {
Session.signInWithValidateCodeAndNavigate(accountID, validateCode, preferredLocale);
Session.signInWithValidateCodeAndNavigate(accountID, validateCode);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
4 changes: 1 addition & 3 deletions src/pages/ValidateLoginPage/index.website.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndica
import ValidateCodeModal from '../../components/ValidateCode/ValidateCodeModal';
import ONYXKEYS from '../../ONYXKEYS';
import * as Session from '../../libs/actions/Session';
import useLocalize from '../../hooks/useLocalize';
import ExpiredValidateCodeModal from '../../components/ValidateCode/ExpiredValidateCodeModal';
import Navigation from '../../libs/Navigation/Navigation';
import CONST from '../../CONST';
Expand Down Expand Up @@ -49,7 +48,6 @@ const defaultProps = {
};

function ValidateLoginPage(props) {
const {preferredLocale} = useLocalize();
const login = lodashGet(props, 'credentials.login', null);
const autoAuthState = lodashGet(props, 'session.autoAuthState', CONST.AUTO_AUTH_STATE.NOT_STARTED);
const accountID = lodashGet(props.route.params, 'accountID', '');
Expand All @@ -71,7 +69,7 @@ function ValidateLoginPage(props) {
}

// The user has initiated the sign in process on the same browser, in another tab.
Session.signInWithValidateCode(accountID, validateCode, preferredLocale);
Session.signInWithValidateCode(accountID, validateCode);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down
11 changes: 3 additions & 8 deletions src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ const propTypes = {
authToken: PropTypes.string,
}),

/** Indicates which locale the user currently has selected */
preferredLocale: PropTypes.string,

/** Information about the network */
network: networkPropTypes.isRequired,

Expand All @@ -76,7 +73,6 @@ const defaultProps = {
session: {
authToken: null,
},
preferredLocale: CONST.LOCALES.DEFAULT,
};

function BaseValidateCodeForm(props) {
Expand Down Expand Up @@ -283,11 +279,11 @@ function BaseValidateCodeForm(props) {

const accountID = lodashGet(props.credentials, 'accountID');
if (accountID) {
Session.signInWithValidateCode(accountID, validateCode, props.preferredLocale, recoveryCodeOr2faCode);
Session.signInWithValidateCode(accountID, validateCode, recoveryCodeOr2faCode);
} else {
Session.signIn(validateCode, recoveryCodeOr2faCode, props.preferredLocale);
Session.signIn(validateCode, recoveryCodeOr2faCode);
}
}, [props.account, props.credentials, props.preferredLocale, twoFactorAuthCode, validateCode, props.isUsingRecoveryCode, recoveryCode]);
}, [props.account, props.credentials, twoFactorAuthCode, validateCode, props.isUsingRecoveryCode, recoveryCode]);

return (
<>
Expand Down Expand Up @@ -404,7 +400,6 @@ export default compose(
withOnyx({
account: {key: ONYXKEYS.ACCOUNT},
credentials: {key: ONYXKEYS.CREDENTIALS},
preferredLocale: {key: ONYXKEYS.NVP_PREFERRED_LOCALE},
session: {key: ONYXKEYS.SESSION},
}),
withNetwork(),
Expand Down

0 comments on commit 3e9fdf6

Please sign in to comment.