@@ -11,6 +11,7 @@ import { useCoreSignIn, useEnvironment } from '../../contexts';
1111import { useAlternativeStrategies } from '../../hooks/useAlternativeStrategies' ;
1212import { localizationKeys } from '../../localization' ;
1313import { useRouter } from '../../router' ;
14+ import type { AlternativeMethodsMode } from './AlternativeMethods' ;
1415import { AlternativeMethods } from './AlternativeMethods' ;
1516import { hasMultipleEnterpriseConnections } from './shared' ;
1617import { SignInFactorOneAlternativePhoneCodeCard } from './SignInFactorOneAlternativePhoneCodeCard' ;
@@ -41,6 +42,25 @@ const factorKey = (factor: SignInFactor | null | undefined) => {
4142 return key ;
4243} ;
4344
45+ function determineAlternativeMethodsMode (
46+ showForgotPasswordStrategies : boolean ,
47+ untrustedPasswordErrorCode : string | null ,
48+ ) : AlternativeMethodsMode {
49+ if ( ! showForgotPasswordStrategies ) {
50+ return 'default' ;
51+ }
52+
53+ if ( untrustedPasswordErrorCode === 'form_password_pwned__sign_in' ) {
54+ return 'pwned' ;
55+ }
56+
57+ if ( untrustedPasswordErrorCode === 'form_password_untrusted__sign_in' ) {
58+ return 'passwordUntrusted' ;
59+ }
60+
61+ return 'forgot' ;
62+ }
63+
4464function SignInFactorOneInternal ( ) : JSX . Element {
4565 const { __internal_setActiveInProgress } = useClerk ( ) ;
4666 const signIn = useCoreSignIn ( ) ;
@@ -84,7 +104,7 @@ function SignInFactorOneInternal(): JSX.Element {
84104
85105 const [ showForgotPasswordStrategies , setShowForgotPasswordStrategies ] = React . useState ( false ) ;
86106
87- const [ isPasswordPwned , setIsPasswordPwned ] = React . useState ( false ) ;
107+ const [ untrustedPasswordErrorCode , setUntrustedPasswordErrorCode ] = React . useState < string | null > ( null ) ;
88108
89109 React . useEffect ( ( ) => {
90110 if ( __internal_setActiveInProgress ) {
@@ -139,11 +159,11 @@ function SignInFactorOneInternal(): JSX.Element {
139159 const toggle = showAllStrategies ? toggleAllStrategies : toggleForgotPasswordStrategies ;
140160 const backHandler = ( ) => {
141161 card . setError ( undefined ) ;
142- setIsPasswordPwned ( false ) ;
162+ setUntrustedPasswordErrorCode ( null ) ;
143163 toggle ?.( ) ;
144164 } ;
145165
146- const mode = showForgotPasswordStrategies ? ( isPasswordPwned ? 'pwned' : 'forgot' ) : 'default' ;
166+ const mode = determineAlternativeMethodsMode ( showForgotPasswordStrategies , untrustedPasswordErrorCode ) ;
147167
148168 return (
149169 < AlternativeMethods
@@ -175,8 +195,8 @@ function SignInFactorOneInternal(): JSX.Element {
175195 < SignInFactorOnePasswordCard
176196 onForgotPasswordMethodClick = { resetPasswordFactor ? toggleForgotPasswordStrategies : toggleAllStrategies }
177197 onShowAlternativeMethodsClick = { toggleAllStrategies }
178- onPasswordPwned = { ( ) => {
179- setIsPasswordPwned ( true ) ;
198+ onUntrustedPassword = { errorCode => {
199+ setUntrustedPasswordErrorCode ( errorCode ) ;
180200 toggleForgotPasswordStrategies ( ) ;
181201 } }
182202 />
0 commit comments