@@ -75,36 +75,57 @@ export default function WorldIdVerify({ token, handle, wallet }: Props) {
7575 const handleVerify = useCallback ( async ( idkitResult : IDKitResult ) => {
7676 console . log ( 'IDKit result:' , JSON . stringify ( idkitResult ) ) ;
7777
78- // Step 1: Verify with World ID API (from browser — CF Workers are IP-blocked)
79- const verifyRes = await fetch ( WORLD_ID_VERIFY_URL , {
80- method : 'POST' ,
81- headers : { 'Content-Type' : 'application/json' } ,
82- body : JSON . stringify ( idkitResult ) ,
83- } ) ;
84-
85- const verifyData = await verifyRes . json ( ) as any ;
86- console . log ( 'World ID verify response:' , verifyRes . status , verifyData ) ;
87-
88- if ( ! verifyRes . ok || ! verifyData . success ) {
89- throw new Error ( verifyData . detail || verifyData . code || 'World ID verification failed' ) ;
90- }
78+ try {
79+ // Step 1: Verify with World ID API (from browser — CF Workers are IP-blocked)
80+ let verifyData : any ;
81+ try {
82+ const verifyRes = await fetch ( WORLD_ID_VERIFY_URL , {
83+ method : 'POST' ,
84+ headers : { 'Content-Type' : 'application/json' } ,
85+ body : JSON . stringify ( idkitResult ) ,
86+ } ) ;
87+ verifyData = await verifyRes . json ( ) ;
88+ console . log ( 'World ID verify response:' , verifyRes . status , verifyData ) ;
89+
90+ if ( ! verifyRes . ok || ! verifyData . success ) {
91+ const msg = `World ID API: ${ verifyData . detail || verifyData . code || verifyRes . status } ` ;
92+ setError ( msg ) ;
93+ throw new Error ( msg ) ;
94+ }
95+ } catch ( fetchErr : any ) {
96+ // CORS or network error
97+ if ( ! fetchErr . message ?. startsWith ( 'World ID API:' ) ) {
98+ const msg = `World ID fetch error (likely CORS): ${ fetchErr . message } ` ;
99+ console . error ( msg ) ;
100+ setError ( msg ) ;
101+ throw new Error ( msg ) ;
102+ }
103+ throw fetchErr ;
104+ }
105+
106+ // Step 2: Store in our backend
107+ const storeRes = await fetch ( `${ API_BASE } /api/world-id/verify` , {
108+ method : 'POST' ,
109+ headers : {
110+ 'Content-Type' : 'application/json' ,
111+ 'Authorization' : `Bearer ${ token } ` ,
112+ } ,
113+ body : JSON . stringify ( {
114+ idkit_result : idkitResult ,
115+ verify_result : verifyData ,
116+ } ) ,
117+ } ) ;
91118
92- // Step 2: Store in our backend
93- const storeRes = await fetch ( `${ API_BASE } /api/world-id/verify` , {
94- method : 'POST' ,
95- headers : {
96- 'Content-Type' : 'application/json' ,
97- 'Authorization' : `Bearer ${ token } ` ,
98- } ,
99- body : JSON . stringify ( {
100- idkit_result : idkitResult ,
101- verify_result : verifyData ,
102- } ) ,
103- } ) ;
104-
105- const storeData = await storeRes . json ( ) as any ;
106- if ( ! storeRes . ok ) {
107- throw new Error ( storeData . error || 'Failed to store verification' ) ;
119+ const storeData = await storeRes . json ( ) as any ;
120+ if ( ! storeRes . ok ) {
121+ const msg = `Backend store: ${ storeData . error || storeRes . status } ` ;
122+ setError ( msg ) ;
123+ throw new Error ( msg ) ;
124+ }
125+ } catch ( e : any ) {
126+ // Error already set in setError above
127+ console . error ( 'handleVerify failed:' , e ) ;
128+ throw e ;
108129 }
109130 } , [ token ] ) ;
110131
0 commit comments