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' ;
66import { RouteComponentProps , useLocation } from '@reach/router' ;
77import { FtlMsg } from 'fxa-react/lib/utils' ;
8- import { isWebIntegration , useFtlMsgResolver } from '../../../models' ;
8+ import { AppContext , isWebIntegration , useFtlMsgResolver } from '../../../models' ;
99import { BackupCodesImage } from '../../../components/images' ;
1010import LinkExternal from 'fxa-react/components/LinkExternal' ;
1111import FormVerifyCode , {
@@ -25,6 +25,7 @@ import Banner from '../../../components/Banner';
2525import { HeadingPrimary } from '../../../components/HeadingPrimary' ;
2626import ButtonBack from '../../../components/ButtonBack' ;
2727import classNames from 'classnames' ;
28+ import { GET_LOCAL_SIGNED_IN_STATUS } from '../../../components/App/gql' ;
2829
2930export 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
0 commit comments