@@ -82,6 +82,7 @@ const secondPhoneFactor: SignInSecondFactorJSON = {
8282 phone_number_id : 'idn_phone' ,
8383 safe_identifier : '+1 555 0100' ,
8484} ;
85+ const secondPasskeyFactor : SignInSecondFactorJSON = { strategy : 'passkey' } ;
8586
8687const TITLE = 'Verification required' ;
8788const NO_FACTORS_TITLE = 'Cannot verify your account' ;
@@ -497,9 +498,22 @@ describe('Reverification', () => {
497498 expect ( await screen . findByText ( STEP . backupCode ) ) . toBeVisible ( ) ;
498499 } ) ;
499500
500- // This is a future behavior we will need to account for, here's the PR that builds it for the existing reverification: https://github.com/clerk/javascript/pull/9127
501- it . todo ( 'offer a passkey listed as a second factor' , ( ) => {
502- // The passkey is not offered on the second factor step
501+ it ( 'starts a supported second factor with passkey before code factors' , async ( ) => {
502+ await renderReverification (
503+ guardedAction ( { level : 'second_factor' , afterMinutes : 10 } ) ,
504+ verificationSeed ( { secondFactors : [ totpFactor , secondPasskeyFactor , secondPhoneFactor ] } ) ,
505+ ) ;
506+ const restore = pretendToBeARealBrowser ( ) ;
507+
508+ try {
509+ const user = await startVerification ( ) ;
510+ expect ( await screen . findByText ( STEP . passkey ) ) . toBeVisible ( ) ;
511+ await useAnotherMethod ( user ) ;
512+ expect ( await screen . findByRole ( 'button' , { name : 'Use your authenticator app' } ) ) . toBeVisible ( ) ;
513+ expect ( screen . getByRole ( 'button' , { name : 'Send SMS code to +1 555 0100' } ) ) . toBeVisible ( ) ;
514+ } finally {
515+ restore ( ) ;
516+ }
503517 } ) ;
504518 } ) ;
505519
@@ -789,6 +803,30 @@ describe('Reverification', () => {
789803 await pasteCode ( user , CODE ) ;
790804 await untilResolved ( ) ;
791805 } ) ;
806+
807+ it ( 'offers an advertised passkey after the first factor of a multi-factor request' , async ( ) => {
808+ const { action, clerk } = await renderReverification (
809+ guardedAction ( { level : 'multi_factor' , afterMinutes : 10 } ) ,
810+ verificationSeed ( { firstFactors : [ passwordFactor ] , secondFactors : [ totpFactor , secondPasskeyFactor ] } ) ,
811+ ) ;
812+ clerk . __internal_getPublicCredentials = vi . fn ( ) . mockResolvedValue ( {
813+ publicKeyCredential : fakeAssertion ( ) ,
814+ error : null ,
815+ } ) ;
816+ const restore = pretendToBeARealBrowser ( ) ;
817+
818+ try {
819+ const user = await startVerification ( ) ;
820+ expect ( await screen . findByText ( STEP . password ) ) . toBeVisible ( ) ;
821+ await user . type ( passwordField ( ) , `${ PASSWORD } {Enter}` ) ;
822+ expect ( await screen . findByText ( STEP . passkey ) ) . toBeVisible ( ) ;
823+ await user . click ( screen . getByRole ( 'button' , { name : 'Continue' } ) ) ;
824+ await untilResolved ( ) ;
825+ expect ( action ) . toHaveBeenCalledTimes ( 2 ) ;
826+ } finally {
827+ restore ( ) ;
828+ }
829+ } ) ;
792830 } ) ;
793831
794832 describe ( 'second factor alternatives' , ( ) => {
@@ -838,12 +876,36 @@ describe('Reverification', () => {
838876 } ) ;
839877 } ) ;
840878
841- describe ( 'passkey' , ( ) => {
879+ describe . each ( [
880+ {
881+ stage : 'first factor' ,
882+ action : ( ) => guardedAction ( ) ,
883+ seed : { firstFactors : [ passwordFactor , passkeyFactor ] } ,
884+ verifiedOn : 'firstFactorVerification' as const ,
885+ skippedOn : 'secondFactorVerification' as const ,
886+ otherMethod : { name : 'Continue with your password' , step : STEP . password } ,
887+ withoutWebAuthn : {
888+ seed : { firstFactors : [ passwordFactor , passkeyFactor , emailFactor ] } ,
889+ step : STEP . password ,
890+ alternative : 'Email code to alice@example.com' ,
891+ } ,
892+ } ,
893+ {
894+ stage : 'second factor' ,
895+ action : ( ) => guardedAction ( { level : 'second_factor' , afterMinutes : 10 } ) ,
896+ seed : { secondFactors : [ totpFactor , secondPasskeyFactor ] } ,
897+ verifiedOn : 'secondFactorVerification' as const ,
898+ skippedOn : 'firstFactorVerification' as const ,
899+ otherMethod : { name : 'Use your authenticator app' , step : STEP . totp } ,
900+ withoutWebAuthn : {
901+ seed : { secondFactors : [ totpFactor , secondPasskeyFactor , backupCodeFactor ] } ,
902+ step : STEP . totp ,
903+ alternative : 'Use a backup code' ,
904+ } ,
905+ } ,
906+ ] ) ( 'passkey as the $stage' , ( { action, seed, verifiedOn, skippedOn, otherMethod, withoutWebAuthn } ) => {
842907 it ( 'completes the challenge with the passkey' , async ( ) => {
843- const { clerk } = await renderReverification (
844- guardedAction ( ) ,
845- verificationSeed ( { firstFactors : [ passwordFactor , passkeyFactor ] } ) ,
846- ) ;
908+ const { clerk, fapi } = await renderReverification ( action ( ) , verificationSeed ( seed ) ) ;
847909 let acceptCredential : ( ) => void = ( ) => { } ;
848910 const getCredential = vi
849911 . fn ( )
@@ -882,16 +944,15 @@ describe('Reverification', () => {
882944 await waitFor ( ( ) => expect ( getCredential ) . toHaveBeenCalledTimes ( 2 ) ) ;
883945 acceptCredential ( ) ;
884946 await untilResolved ( ) ;
947+ expect ( fapi . verification [ verifiedOn ] ?. strategy ) . toBe ( 'passkey' ) ;
948+ expect ( fapi . verification [ skippedOn ] ) . toBeNull ( ) ;
885949 } finally {
886950 restore ( ) ;
887951 }
888952 } ) ;
889953
890954 it ( 'shows no error when the passkey prompt is aborted' , async ( ) => {
891- const { clerk } = await renderReverification (
892- guardedAction ( ) ,
893- verificationSeed ( { firstFactors : [ passwordFactor , passkeyFactor ] } ) ,
894- ) ;
955+ const { clerk } = await renderReverification ( action ( ) , verificationSeed ( seed ) ) ;
895956 const getCredential = vi . fn ( ) . mockResolvedValue ( {
896957 publicKeyCredential : null ,
897958 error : new ClerkWebAuthnError ( 'The operation was aborted' , { code : 'passkey_operation_aborted' } ) ,
@@ -917,10 +978,7 @@ describe('Reverification', () => {
917978 } ) ;
918979
919980 it ( 'clears an earlier passkey error when the next prompt is aborted' , async ( ) => {
920- const { clerk } = await renderReverification (
921- guardedAction ( ) ,
922- verificationSeed ( { firstFactors : [ passwordFactor , passkeyFactor ] } ) ,
923- ) ;
981+ const { clerk } = await renderReverification ( action ( ) , verificationSeed ( seed ) ) ;
924982 const getCredential = vi
925983 . fn ( )
926984 . mockResolvedValueOnce ( {
@@ -955,15 +1013,15 @@ describe('Reverification', () => {
9551013 } ) ;
9561014
9571015 it ( 'offers the passkey from the picker when another method is showing' , async ( ) => {
958- await renderReverification ( guardedAction ( ) , verificationSeed ( { firstFactors : [ passwordFactor , passkeyFactor ] } ) ) ;
1016+ await renderReverification ( action ( ) , verificationSeed ( seed ) ) ;
9591017 const restore = pretendToBeARealBrowser ( ) ;
9601018
9611019 try {
9621020 const user = await startVerification ( ) ;
9631021 expect ( await screen . findByText ( STEP . passkey ) ) . toBeVisible ( ) ;
9641022 await useAnotherMethod ( user ) ;
965- await user . click ( await screen . findByRole ( 'button' , { name : 'Continue with your password' } ) ) ;
966- expect ( await screen . findByText ( STEP . password ) ) . toBeVisible ( ) ;
1023+ await user . click ( await screen . findByRole ( 'button' , { name : otherMethod . name } ) ) ;
1024+ expect ( await screen . findByText ( otherMethod . step ) ) . toBeVisible ( ) ;
9671025
9681026 // The passkey is listed once the user is on another method
9691027 await useAnotherMethod ( user ) ;
@@ -975,20 +1033,17 @@ describe('Reverification', () => {
9751033 } ) ;
9761034
9771035 it ( 'does not offer a passkey when the browser does not support WebAuthn' , async ( ) => {
978- await renderReverification (
979- guardedAction ( ) ,
980- verificationSeed ( { firstFactors : [ passwordFactor , passkeyFactor , emailFactor ] } ) ,
981- ) ;
1036+ await renderReverification ( action ( ) , verificationSeed ( withoutWebAuthn . seed ) ) ;
9821037 const restore = pretendWebAuthnIsUnsupported ( ) ;
9831038
9841039 try {
9851040 // The passkey is not the starting method
9861041 const user = await startVerification ( ) ;
987- expect ( await screen . findByText ( STEP . password ) ) . toBeVisible ( ) ;
1042+ expect ( await screen . findByText ( withoutWebAuthn . step ) ) . toBeVisible ( ) ;
9881043
9891044 // The passkey is not listed in the picker
9901045 await useAnotherMethod ( user ) ;
991- expect ( await screen . findByRole ( 'button' , { name : 'Email code to alice@example.com' } ) ) . toBeVisible ( ) ;
1046+ expect ( await screen . findByRole ( 'button' , { name : withoutWebAuthn . alternative } ) ) . toBeVisible ( ) ;
9921047 expect ( screen . queryByRole ( 'button' , { name : 'Use your passkey' } ) ) . toBeNull ( ) ;
9931048 } finally {
9941049 restore ( ) ;
0 commit comments