@@ -417,14 +417,9 @@ function AuthEndpointFields(props: {
417417 canEditAdvancedFeatures : boolean ;
418418} ) {
419419 const { form, canEditAdvancedFeatures } = props ;
420- const customHeaderFields = useFieldArray ( {
421- control : form . control ,
422- name : "customAuthEndpoint.customHeaders" ,
423- } ) ;
424420
425421 const expandCustomAuthEndpointField =
426- form . watch ( "customAuthEndpoint" ) ?. authEndpoint !== undefined &&
427- canEditAdvancedFeatures ;
422+ form . watch ( "customAuthEndpoint" ) !== undefined && canEditAdvancedFeatures ;
428423
429424 return (
430425 < div >
@@ -464,88 +459,107 @@ function AuthEndpointFields(props: {
464459 } }
465460 />
466461 </ SwitchContainer >
462+ { /* useFieldArray used on this component - it creates empty customAuthEndpoint.customHeaders array on mount */ }
463+ { /* So only mount if expandCustomAuthEndpointField is true */ }
464+ { expandCustomAuthEndpointField && (
465+ < AuthEndpointFieldsContent
466+ form = { form }
467+ canEditAdvancedFeatures = { canEditAdvancedFeatures }
468+ />
469+ ) }
470+ </ div >
471+ ) ;
472+ }
467473
468- < AdvancedConfigurationContainer
469- show = { expandCustomAuthEndpointField }
470- className = "grid grid-cols-1 gap-6 lg:grid-cols-2"
471- >
472- < FormField
473- control = { form . control }
474- name = "customAuthEndpoint.authEndpoint"
475- render = { ( { field } ) => (
476- < FormItem >
477- < FormLabel > Authentication Endpoint</ FormLabel >
478- < FormControl >
474+ function AuthEndpointFieldsContent ( props : {
475+ form : UseFormReturn < ApiKeyEmbeddedWalletsValidationSchema > ;
476+ canEditAdvancedFeatures : boolean ;
477+ } ) {
478+ const { form } = props ;
479+
480+ const customHeaderFields = useFieldArray ( {
481+ control : form . control ,
482+ name : "customAuthEndpoint.customHeaders" ,
483+ } ) ;
484+
485+ return (
486+ < div className = "mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2" >
487+ < FormField
488+ control = { form . control }
489+ name = "customAuthEndpoint.authEndpoint"
490+ render = { ( { field } ) => (
491+ < FormItem >
492+ < FormLabel > Authentication Endpoint</ FormLabel >
493+ < FormControl >
494+ < Input
495+ { ...field }
496+ placeholder = "https://example.com/your-auth-verifier"
497+ />
498+ </ FormControl >
499+ < FormDescription >
500+ Enter the URL of your server where we will send the user payload
501+ for verification
502+ </ FormDescription >
503+ < FormMessage />
504+ </ FormItem >
505+ ) }
506+ />
507+
508+ < div >
509+ < Label className = "mb-3 inline-block" > Custom Headers</ Label >
510+ < div className = "flex flex-col gap-4" >
511+ { customHeaderFields . fields . map ( ( field , customHeaderIdx ) => {
512+ return (
513+ < div className = "flex gap-4" key = { field . id } >
479514 < Input
480- { ...field }
481- placeholder = "https://example.com/your-auth-verifier"
515+ placeholder = "Name"
516+ type = "text"
517+ { ...form . register (
518+ `customAuthEndpoint.customHeaders.${ customHeaderIdx } .key` ,
519+ ) }
482520 />
483- </ FormControl >
484- < FormDescription >
485- Enter the URL of your server where we will send the user payload
486- for verification
487- </ FormDescription >
488- < FormMessage />
489- </ FormItem >
490- ) }
491- />
492-
493- < div >
494- < Label className = "mb-3 inline-block" > Custom Headers</ Label >
495- < div className = "flex flex-col gap-4" >
496- { customHeaderFields . fields . map ( ( field , customHeaderIdx ) => {
497- return (
498- < div className = "flex gap-4" key = { field . id } >
499- < Input
500- placeholder = "Name"
501- type = "text"
502- { ...form . register (
503- `customAuthEndpoint.customHeaders.${ customHeaderIdx } .key` ,
504- ) }
505- />
506- < Input
507- placeholder = "Value"
508- type = "text"
509- { ...form . register (
510- `customAuthEndpoint.customHeaders.${ customHeaderIdx } .value` ,
511- ) }
512- />
513- < Button
514- variant = "outline"
515- aria-label = "Remove header"
516- onClick = { ( ) => {
517- customHeaderFields . remove ( customHeaderIdx ) ;
518- } }
519- className = "!w-auto px-3"
520- >
521- < Trash2Icon className = "size-4 shrink-0 text-destructive-text" />
522- </ Button >
523- </ div >
524- ) ;
525- } ) }
526-
527- < Button
528- variant = "outline"
529- className = "w-full gap-2 bg-background"
530- onClick = { ( ) => {
531- customHeaderFields . append ( {
532- key : "" ,
533- value : "" ,
534- } ) ;
535- } }
536- >
537- < PlusIcon className = "size-4" />
538- Add header
539- </ Button >
540- </ div >
541-
542- < p className = "mt-3 text-muted-foreground text-sm" >
543- Set custom headers to be sent along the request with the payload to
544- the authentication endpoint above. This can be used to verify the
545- incoming requests
546- </ p >
521+ < Input
522+ placeholder = "Value"
523+ type = "text"
524+ { ...form . register (
525+ `customAuthEndpoint.customHeaders.${ customHeaderIdx } .value` ,
526+ ) }
527+ />
528+ < Button
529+ variant = "outline"
530+ aria-label = "Remove header"
531+ onClick = { ( ) => {
532+ customHeaderFields . remove ( customHeaderIdx ) ;
533+ } }
534+ className = "!w-auto px-3"
535+ >
536+ < Trash2Icon className = "size-4 shrink-0 text-destructive-text" />
537+ </ Button >
538+ </ div >
539+ ) ;
540+ } ) }
541+
542+ < Button
543+ variant = "outline"
544+ className = "w-full gap-2 bg-background"
545+ onClick = { ( ) => {
546+ customHeaderFields . append ( {
547+ key : "" ,
548+ value : "" ,
549+ } ) ;
550+ } }
551+ >
552+ < PlusIcon className = "size-4" />
553+ Add header
554+ </ Button >
547555 </ div >
548- </ AdvancedConfigurationContainer >
556+
557+ < p className = "mt-3 text-muted-foreground text-sm" >
558+ Set custom headers to be sent along the request with the payload to
559+ the authentication endpoint above. This can be used to verify the
560+ incoming requests
561+ </ p >
562+ </ div >
549563 </ div >
550564 ) ;
551565}
0 commit comments