1414window . hypha = window . hypha || { } ;
1515
1616window . hypha . passkeys = ( function ( ) {
17+ let _conditionalAbortController = null ;
1718 function getCsrfToken ( ) {
1819 const el = document . querySelector ( "[name=csrfmiddlewaretoken]" ) ;
1920 if ( el ) return el . value ;
@@ -126,6 +127,12 @@ window.hypha.passkeys = (function () {
126127 * Authenticate with a passkey via an explicit button click on the login page.
127128 */
128129 async function authenticate ( ) {
130+ // Abort any in-progress conditional mediation before starting explicit auth.
131+ if ( _conditionalAbortController ) {
132+ _conditionalAbortController . abort ( ) ;
133+ _conditionalAbortController = null ;
134+ }
135+
129136 const beginUrl = document . getElementById ( "passkey-auth-begin-url" ) ?. value ;
130137 const completeUrl = document . getElementById (
131138 "passkey-auth-complete-url"
@@ -182,6 +189,8 @@ window.hypha.passkeys = (function () {
182189 ) ?. value ;
183190 if ( ! beginUrl || ! completeUrl ) return ;
184191
192+ _conditionalAbortController = new AbortController ( ) ;
193+
185194 try {
186195 const beginResp = await jsonPost ( beginUrl , { } ) ;
187196 if ( ! beginResp . ok ) return ;
@@ -192,6 +201,7 @@ window.hypha.passkeys = (function () {
192201 const credential = await navigator . credentials . get ( {
193202 publicKey : PublicKeyCredential . parseRequestOptionsFromJSON ( authOptions ) ,
194203 mediation : "conditional" ,
204+ signal : _conditionalAbortController . signal ,
195205 } ) ;
196206
197207 if ( ! credential ) return ;
0 commit comments