Skip to content

Commit 9f1922a

Browse files
authored
Merge pull request #18456 from mozilla/fxa-11207
fix(sms): Set signed in state to true in apolloClient after using recovery phone and code
2 parents fed0072 + 92b2c9b commit 9f1922a

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

packages/fxa-settings/src/pages/Signin/SigninRecoveryCode/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import React, { useCallback, useEffect, useState } from 'react';
5+
import React, { useCallback, useContext, useEffect, useState } from 'react';
66
import { RouteComponentProps, useLocation } from '@reach/router';
77
import { FtlMsg } from 'fxa-react/lib/utils';
8-
import { isWebIntegration, useFtlMsgResolver } from '../../../models';
8+
import { AppContext, isWebIntegration, useFtlMsgResolver } from '../../../models';
99
import { BackupCodesImage } from '../../../components/images';
1010
import LinkExternal from 'fxa-react/components/LinkExternal';
1111
import FormVerifyCode, {
@@ -25,6 +25,7 @@ import Banner from '../../../components/Banner';
2525
import { HeadingPrimary } from '../../../components/HeadingPrimary';
2626
import ButtonBack from '../../../components/ButtonBack';
2727
import classNames from 'classnames';
28+
import { GET_LOCAL_SIGNED_IN_STATUS } from '../../../components/App/gql';
2829

2930
export const viewName = 'signin-recovery-code';
3031

@@ -52,6 +53,7 @@ const SigninRecoveryCode = ({
5253
'Backup authentication code required'
5354
);
5455
const location = useLocation();
56+
const { apolloClient } = useContext(AppContext);
5557

5658
const webRedirectCheck = useWebRedirect(integration.data.redirectTo);
5759

@@ -143,6 +145,17 @@ const SigninRecoveryCode = ({
143145
// Update verification status of stored current account
144146
verified: true,
145147
});
148+
149+
// There seems to be a race condition with updating the cache and state,
150+
// so we need to wait a bit before navigating to the next page. This is
151+
// a temporary fix until we find a better solution, most likely with refactoring
152+
// how we handle state in the app.
153+
apolloClient?.cache.writeQuery({
154+
query: GET_LOCAL_SIGNED_IN_STATUS,
155+
data: { isSignedIn: true },
156+
});
157+
await new Promise((resolve) => setTimeout(resolve, 100));
158+
146159
onSuccessNavigate();
147160
}
148161

packages/fxa-settings/src/pages/Signin/SigninRecoveryPhone/container.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import React, { useEffect } from 'react';
5+
import React, { useContext, useEffect } from 'react';
66
import { RouteComponentProps, useLocation } from '@reach/router';
77
import SigninRecoveryPhone from '.';
88
import { SigninLocationState } from '../interfaces';
99
import { getSigninState, handleNavigation } from '../utils';
1010
import {
11+
AppContext,
1112
isWebIntegration,
1213
useAuthClient,
1314
useSensitiveDataClient,
@@ -27,11 +28,13 @@ import {
2728
SigninRecoveryPhoneContainerProps,
2829
SigninRecoveryPhoneLocationState,
2930
} from './interfaces';
31+
import { GET_LOCAL_SIGNED_IN_STATUS } from '../../../components/App/gql';
3032

3133
const SigninRecoveryPhoneContainer = ({
3234
integration,
3335
}: SigninRecoveryPhoneContainerProps & RouteComponentProps) => {
3436
const authClient = useAuthClient();
37+
const { apolloClient } = useContext(AppContext);
3538
const location = useLocation() as ReturnType<typeof useLocation> & {
3639
state: SigninRecoveryPhoneLocationState;
3740
};
@@ -84,6 +87,16 @@ const SigninRecoveryPhoneContainer = ({
8487
verified: true,
8588
});
8689

90+
// There seems to be a race condition with updating the cache and state,
91+
// so we need to wait a bit before navigating to the next page. This is
92+
// a temporary fix until we find a better solution, most likely with refactoring
93+
// how we handle state in the app.
94+
apolloClient?.cache.writeQuery({
95+
query: GET_LOCAL_SIGNED_IN_STATUS,
96+
data: { isSignedIn: true },
97+
});
98+
await new Promise((resolve) => setTimeout(resolve, 100));
99+
87100
const navigationOptions = {
88101
email: signinState.email,
89102
signinData: {

0 commit comments

Comments
 (0)