@@ -1020,6 +1020,93 @@ describe('SignIn', () => {
10201020 } ) ,
10211021 ) ;
10221022 } ) ;
1023+
1024+ it ( 'forwards preferImmediatelyAvailableCredentials to the credential request in the discoverable flow' , async ( ) => {
1025+ const mockIsWebAuthnSupported = vi . fn ( ) . mockReturnValue ( true ) ;
1026+ const mockWebAuthnGetCredential = vi . fn ( ) . mockResolvedValue ( {
1027+ publicKeyCredential : mockPublicKeyCredential ,
1028+ error : null ,
1029+ } ) ;
1030+
1031+ SignIn . clerk = {
1032+ __internal_isWebAuthnSupported : mockIsWebAuthnSupported ,
1033+ __internal_getPublicCredentials : mockWebAuthnGetCredential ,
1034+ } as any ;
1035+
1036+ const mockFetch = vi
1037+ . fn ( )
1038+ . mockResolvedValueOnce ( {
1039+ client : null ,
1040+ response : {
1041+ id : 'signin_456' ,
1042+ status : 'needs_first_factor' ,
1043+ first_factor_verification : {
1044+ nonce : JSON . stringify ( { challenge : 'Y2hhbGxlbmdl' } ) ,
1045+ } ,
1046+ } ,
1047+ } )
1048+ . mockResolvedValueOnce ( {
1049+ client : null ,
1050+ response : { id : 'signin_456' , status : 'complete' } ,
1051+ } ) ;
1052+ BaseResource . _fetch = mockFetch ;
1053+
1054+ const signIn = new SignIn ( { id : 'signin_123' } as any ) ;
1055+ await signIn . authenticateWithPasskey ( { flow : 'discoverable' , preferImmediatelyAvailableCredentials : true } ) ;
1056+
1057+ expect ( mockWebAuthnGetCredential ) . toHaveBeenCalledWith (
1058+ expect . objectContaining ( { preferImmediatelyAvailableCredentials : true } ) ,
1059+ ) ;
1060+ } ) ;
1061+
1062+ it ( 'forwards preferImmediatelyAvailableCredentials to the credential request for a passkey second factor' , async ( ) => {
1063+ const mockIsWebAuthnSupported = vi . fn ( ) . mockReturnValue ( true ) ;
1064+ const mockWebAuthnGetCredential = vi . fn ( ) . mockResolvedValue ( {
1065+ publicKeyCredential : mockPublicKeyCredential ,
1066+ error : null ,
1067+ } ) ;
1068+
1069+ SignIn . clerk = {
1070+ __internal_isWebAuthnSupported : mockIsWebAuthnSupported ,
1071+ __internal_getPublicCredentials : mockWebAuthnGetCredential ,
1072+ } as any ;
1073+
1074+ const mockFetch = vi
1075+ . fn ( )
1076+ . mockResolvedValueOnce ( {
1077+ client : null ,
1078+ response : {
1079+ id : 'signin_123' ,
1080+ status : 'needs_second_factor' ,
1081+ supported_second_factors : [ { strategy : 'passkey' } ] ,
1082+ second_factor_verification : {
1083+ nonce : JSON . stringify ( { challenge : 'Y2hhbGxlbmdl' } ) ,
1084+ } ,
1085+ } ,
1086+ } )
1087+ . mockResolvedValueOnce ( {
1088+ client : null ,
1089+ response : { id : 'signin_123' , status : 'complete' } ,
1090+ } ) ;
1091+ BaseResource . _fetch = mockFetch ;
1092+
1093+ const signIn = new SignIn ( {
1094+ id : 'signin_123' ,
1095+ status : 'needs_second_factor' ,
1096+ supported_second_factors : [ { strategy : 'passkey' } , { strategy : 'totp' } ] ,
1097+ } as any ) ;
1098+ await signIn . authenticateWithPasskey ( { preferImmediatelyAvailableCredentials : true } ) ;
1099+
1100+ expect ( mockFetch ) . toHaveBeenNthCalledWith (
1101+ 1 ,
1102+ expect . objectContaining ( {
1103+ path : '/client/sign_ins/signin_123/prepare_second_factor' ,
1104+ } ) ,
1105+ ) ;
1106+ expect ( mockWebAuthnGetCredential ) . toHaveBeenCalledWith (
1107+ expect . objectContaining ( { preferImmediatelyAvailableCredentials : true } ) ,
1108+ ) ;
1109+ } ) ;
10231110 } ) ;
10241111
10251112 describe ( 'trusted_device strategy' , ( ) => {
@@ -2593,6 +2680,58 @@ describe('SignIn', () => {
25932680 expect ( mockWebAuthnGetCredential ) . toHaveBeenCalled ( ) ;
25942681 } ) ;
25952682
2683+ it ( 'forwards preferImmediatelyAvailableCredentials to the credential request' , async ( ) => {
2684+ const mockIsWebAuthnSupported = vi . fn ( ) . mockReturnValue ( true ) ;
2685+ const mockWebAuthnGetCredential = vi . fn ( ) . mockResolvedValue ( {
2686+ publicKeyCredential : {
2687+ id : 'credential_123' ,
2688+ rawId : new ArrayBuffer ( 32 ) ,
2689+ response : {
2690+ authenticatorData : new ArrayBuffer ( 37 ) ,
2691+ clientDataJSON : new ArrayBuffer ( 121 ) ,
2692+ signature : new ArrayBuffer ( 64 ) ,
2693+ userHandle : null ,
2694+ } ,
2695+ type : 'public-key' ,
2696+ } ,
2697+ error : null ,
2698+ } ) ;
2699+
2700+ SignIn . clerk = {
2701+ __internal_isWebAuthnSupported : mockIsWebAuthnSupported ,
2702+ __internal_getPublicCredentials : mockWebAuthnGetCredential ,
2703+ __internal_environment : {
2704+ displayConfig : {
2705+ captchaOauthBypass : [ ] ,
2706+ } ,
2707+ } ,
2708+ } as any ;
2709+
2710+ const mockFetch = vi
2711+ . fn ( )
2712+ . mockResolvedValueOnce ( {
2713+ client : null ,
2714+ response : {
2715+ id : 'signin_123' ,
2716+ first_factor_verification : {
2717+ nonce : JSON . stringify ( { challenge : 'Y2hhbGxlbmdl' } ) ,
2718+ } ,
2719+ } ,
2720+ } )
2721+ . mockResolvedValueOnce ( {
2722+ client : null ,
2723+ response : { id : 'signin_123' , status : 'complete' } ,
2724+ } ) ;
2725+ BaseResource . _fetch = mockFetch ;
2726+
2727+ const signIn = new SignIn ( ) ;
2728+ await signIn . __internal_future . passkey ( { flow : 'discoverable' , preferImmediatelyAvailableCredentials : true } ) ;
2729+
2730+ expect ( mockWebAuthnGetCredential ) . toHaveBeenCalledWith (
2731+ expect . objectContaining ( { preferImmediatelyAvailableCredentials : true } ) ,
2732+ ) ;
2733+ } ) ;
2734+
25962735 it ( 'throws error when WebAuthn is not supported' , async ( ) => {
25972736 const mockIsWebAuthnSupported = vi . fn ( ) . mockReturnValue ( false ) ;
25982737
0 commit comments