@@ -15,15 +15,13 @@ import { renderCallbacks } from './callback-map.js';
1515import { renderDeleteDevicesSection } from './components/delete-device.js' ;
1616import { renderQRCodeStep } from './components/qr-code.js' ;
1717import { renderRecoveryCodesStep } from './components/recovery-codes.js' ;
18- import { deleteWebAuthnDevice } from './services/delete-webauthn-devices .js' ;
19- import { webauthnComponent } from './components/webauthn.js' ;
18+ import { deleteWebAuthnDevice } from './services/delete-webauthn-device .js' ;
19+ import { webauthnComponent } from './components/webauthn-step .js' ;
2020import { serverConfigs } from './server-configs.js' ;
2121
2222const qs = window . location . search ;
2323const searchParams = new URLSearchParams ( qs ) ;
2424
25- const WEBAUTHN_CREDENTIAL_ID_QUERY_PARAM = 'webauthnCredentialId' ;
26-
2725const config = serverConfigs [ searchParams . get ( 'clientId' ) || 'basic' ] ;
2826
2927const journeyName = searchParams . get ( 'journey' ) ?? 'UsernamePassword' ;
@@ -65,24 +63,6 @@ if (searchParams.get('middleware') === 'true') {
6563 const formEl = document . getElementById ( 'form' ) as HTMLFormElement ;
6664 const journeyEl = document . getElementById ( 'journey' ) as HTMLDivElement ;
6765
68- const getCredentialIdFromUrl = ( ) : string | null => {
69- const params = new URLSearchParams ( window . location . search ) ;
70- const value = params . get ( WEBAUTHN_CREDENTIAL_ID_QUERY_PARAM ) ;
71- return value && value . length > 0 ? value : null ;
72- } ;
73-
74- const setCredentialIdInUrl = ( credentialId : string | null ) : void => {
75- const url = new URL ( window . location . href ) ;
76- if ( credentialId ) {
77- url . searchParams . set ( WEBAUTHN_CREDENTIAL_ID_QUERY_PARAM , credentialId ) ;
78- } else {
79- url . searchParams . delete ( WEBAUTHN_CREDENTIAL_ID_QUERY_PARAM ) ;
80- }
81- window . history . replaceState ( { } , document . title , url . toString ( ) ) ;
82- } ;
83-
84- let registrationCredentialId : string | null = getCredentialIdFromUrl ( ) ;
85-
8666 let journeyClient : JourneyClient ;
8767 try {
8868 journeyClient = await journey ( { config, requestMiddleware } ) ;
@@ -134,13 +114,8 @@ if (searchParams.get('middleware') === 'true') {
134114 webAuthnStep === WebAuthnStepType . Authentication ||
135115 webAuthnStep === WebAuthnStepType . Registration
136116 ) {
137- const webAuthnResponse = await webauthnComponent ( journeyEl , step , 0 ) ;
138- if ( webAuthnResponse . success ) {
139- if ( webAuthnResponse . credentialId ) {
140- registrationCredentialId = webAuthnResponse . credentialId ;
141- setCredentialIdInUrl ( registrationCredentialId ) ;
142- console . log ( '[WebAuthn] stored registration credentialId:' , registrationCredentialId ) ;
143- }
117+ const webAuthnSuccess = await webauthnComponent ( journeyEl , step , 0 ) ;
118+ if ( webAuthnSuccess ) {
144119 submitForm ( ) ;
145120 return ;
146121 } else {
@@ -180,9 +155,7 @@ if (searchParams.get('middleware') === 'true') {
180155 completeHeader . innerText = 'Complete' ;
181156 journeyEl . appendChild ( completeHeader ) ;
182157
183- renderDeleteDevicesSection ( journeyEl , ( ) =>
184- deleteWebAuthnDevice ( config , registrationCredentialId ) ,
185- ) ;
158+ renderDeleteDevicesSection ( journeyEl , ( ) => deleteWebAuthnDevice ( config ) ) ;
186159
187160 const sessionLabelEl = document . createElement ( 'span' ) ;
188161 sessionLabelEl . id = 'sessionLabel' ;
0 commit comments