@@ -7,7 +7,7 @@ import { useNavigateWithQuery } from '../../lib/hooks/useNavigateWithQuery';
77import classNames from 'classnames' ;
88import LoadingSpinner from 'fxa-react/components/LoadingSpinner' ;
99import { FtlMsg } from 'fxa-react/lib/utils' ;
10- import React , { useCallback , useEffect , useRef , useState } from 'react' ;
10+ import React , { useCallback , useEffect , useState } from 'react' ;
1111import { useForm } from 'react-hook-form' ;
1212import AppLayout from '../../components/AppLayout' ;
1313import CardHeader from '../../components/CardHeader' ;
@@ -92,12 +92,14 @@ const Signin = ({
9292 const isServiceWithEmailVerification =
9393 ! ! clientId && config . servicesWithEmailVerification . includes ( clientId ) ;
9494
95- // We must use a ref because we may update this value in a callback
96- let isPasswordNeededRef = useRef (
97- ( ! sessionToken && hasPassword ) ||
95+ const [ hasCachedAccount , setHasCachedAccount ] =
96+ useState < boolean > ( ! ! sessionToken ) ;
97+
98+ const isPasswordNeeded =
99+ ( ( ! hasCachedAccount && hasPassword ) ||
98100 integration . wantsKeys ( ) ||
99- ( isOAuth && integration . wantsLogin ( ) )
100- ) ;
101+ ( isOAuth && integration . wantsLogin ( ) ) ) &&
102+ ! ( hasCachedAccount && supportsKeysOptionalLogin ) ;
101103
102104 const localizedPasswordFormLabel = ftlMsgResolver . getMsg (
103105 'signin-password-button-label' ,
@@ -127,7 +129,7 @@ const Signin = ({
127129 : isOAuthNative && ! supportsKeysOptionalLogin ;
128130
129131 useEffect ( ( ) => {
130- if ( ! isPasswordNeededRef . current ) {
132+ if ( ! isPasswordNeeded ) {
131133 GleanMetrics . cachedLogin . view ( {
132134 event : { thirdPartyLinks : ! hideThirdPartyAuth } ,
133135 } ) ;
@@ -136,7 +138,7 @@ const Signin = ({
136138 event : { thirdPartyLinks : ! hideThirdPartyAuth } ,
137139 } ) ;
138140 }
139- } , [ isPasswordNeededRef , hideThirdPartyAuth ] ) ;
141+ } , [ isPasswordNeeded , hideThirdPartyAuth ] ) ;
140142
141143 const signInWithCachedAccount = useCallback (
142144 async ( sessionToken : hexstring ) => {
@@ -167,6 +169,8 @@ const Signin = ({
167169 queryParams : location . search ,
168170 performNavigation : ! integration . isFirefoxMobileClient ( ) ,
169171 isServiceWithEmailVerification,
172+ handleFxaLogin : true ,
173+ handleFxaOAuthLogin : true ,
170174 } ;
171175
172176 const { error : navError } = await handleNavigation ( navigationOptions ) ;
@@ -181,7 +185,7 @@ const Signin = ({
181185 getLocalizedErrorMessage ( ftlMsgResolver , error )
182186 ) ;
183187 if ( error . errno === AuthUiErrors . SESSION_EXPIRED . errno ) {
184- isPasswordNeededRef . current = true ;
188+ setHasCachedAccount ( false ) ;
185189 }
186190 setSigninLoading ( false ) ;
187191 }
@@ -339,19 +343,19 @@ const Signin = ({
339343
340344 const onSubmit = useCallback (
341345 async ( { password } : { password : string } ) => {
342- if ( isPasswordNeededRef . current && password === '' ) {
346+ if ( isPasswordNeeded && password === '' ) {
343347 setPasswordTooltipErrorText ( localizedValidPasswordError ) ;
344348 return ;
345349 }
346350
347- ! isPasswordNeededRef . current && sessionToken
351+ ! isPasswordNeeded && sessionToken
348352 ? signInWithCachedAccount ( sessionToken )
349353 : signInWithPassword ( password ) ;
350354 } ,
351355 [
352356 signInWithCachedAccount ,
353357 signInWithPassword ,
354- isPasswordNeededRef ,
358+ isPasswordNeeded ,
355359 localizedValidPasswordError ,
356360 sessionToken ,
357361 ]
@@ -372,7 +376,7 @@ const Signin = ({
372376 } }
373377 />
374378 ) }
375- { isPasswordNeededRef . current && hasPassword ? (
379+ { isPasswordNeeded && hasPassword ? (
376380 < CardHeader
377381 headingText = "Enter your password"
378382 headingAndSubheadingFtlId = "signin-password-needed-header-2"
@@ -441,11 +445,12 @@ const Signin = ({
441445 </ FtlMsg >
442446 ) }
443447 </ div >
444- { ! hasLinkedAccountAndNoPassword && (
448+ { ( ! hasLinkedAccountAndNoPassword ||
449+ ( hasCachedAccount && supportsKeysOptionalLogin ) ) && (
445450 < form onSubmit = { handleSubmit ( onSubmit ) } >
446451 < input type = "email" className = "hidden" value = { email } disabled />
447452
448- { isPasswordNeededRef . current && (
453+ { isPasswordNeeded && (
449454 < InputPassword
450455 name = "password"
451456 anchorPosition = "start"
@@ -538,7 +543,7 @@ const Signin = ({
538543 } `}
539544 className = "text-sm link-blue mx-auto tablet:mx-0"
540545 onClick = { ( ) =>
541- ! isPasswordNeededRef . current
546+ ! isPasswordNeeded
542547 ? GleanMetrics . cachedLogin . forgotPassword ( )
543548 : GleanMetrics . login . forgotPassword ( )
544549 }
0 commit comments