@@ -103,7 +103,12 @@ import { getAuth, RecaptchaVerifier, signInWithPhoneNumber, signOut } from "http
103103 } ) ;
104104 let payload = { } ;
105105 try { payload = await response . json ( ) ; } catch ( _ ) { /* generic failure below */ }
106- if ( ! response . ok ) throw new Error ( payload . error || "The request could not be completed." ) ;
106+ if ( ! response . ok ) {
107+ const error = new Error ( payload . error || "The request could not be completed." ) ;
108+ error . source = "api" ;
109+ error . status = response . status ;
110+ throw error ;
111+ }
107112 return payload ;
108113 }
109114
@@ -148,6 +153,9 @@ import { getAuth, RecaptchaVerifier, signInWithPhoneNumber, signOut } from "http
148153 isTokenAutoRefreshEnabled : true
149154 } ) ;
150155 state . firebaseAuth = getAuth ( firebaseApp ) ;
156+ // Firebase's documented test mode accepts only fictional numbers that are
157+ // explicitly registered in the console. Never enable this for production.
158+ if ( config . pilotMode ) state . firebaseAuth . settings . appVerificationDisabledForTesting = true ;
151159 state . firebaseAuth . useDeviceLanguage ( ) ;
152160 state . firebaseRecaptcha = new RecaptchaVerifier ( state . firebaseAuth , "send-code-button" , { size : "invisible" } ) ;
153161 }
@@ -247,6 +255,13 @@ import { getAuth, RecaptchaVerifier, signInWithPhoneNumber, signOut } from "http
247255 setNotice ( "Verification code sent. It expires in 10 minutes." , "ok" ) ;
248256 document . getElementById ( "verification-code" ) . focus ( ) ;
249257 } catch ( error ) {
258+ if ( error && error . source === "api" ) {
259+ setNotice ( config . pilotMode
260+ ? `Pilot API error: ${ error . message } `
261+ : "Unable to begin verification. Please try again later." , "error" ) ;
262+ if ( window . turnstile && state . turnstileWidgetId !== null ) window . turnstile . reset ( state . turnstileWidgetId ) ;
263+ return ;
264+ }
250265 const firebaseCode = error && typeof error . code === "string" ? error . code : "unknown" ;
251266 if ( config . pilotMode ) console . error ( "pilot_phone_auth_failed" , firebaseCode , error ) ;
252267 setNotice ( config . pilotMode
0 commit comments