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 Sign in- Language preference doesn't persist when user Signs in with google #26948

Merged
merged 5 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading