@@ -90,23 +90,23 @@ export const FormContents = ({
9090    if  ( values . http_url  &&  isEdgeFunctionSelected )  { 
9191      const  fnSlug  =  values . http_url . split ( '/' ) . at ( - 1 ) 
9292      const  fn  =  functions . find ( ( x )  =>  x . slug  ===  fnSlug ) 
93+       const  authorizationHeader  =  httpHeaders . find ( ( x )  =>  x . name  ===  'Authorization' ) 
94+       const  edgeFunctionAuthHeaderVal  =  `Bearer ${ legacyServiceRole }  
9395
94-       if  ( fn ?. verify_jwt )  { 
95-         if  ( ! httpHeaders . some ( ( x )  =>  x . name  ===  'Authorization' ) )  { 
96-           const  authorizationHeader  =  { 
97-             id : uuidv4 ( ) , 
98-             name : 'Authorization' , 
99-             value : `Bearer ${ legacyServiceRole }  , 
100-           } 
101-           setHttpHeaders ( [ ...httpHeaders ,  authorizationHeader ] ) 
96+       if  ( fn ?. verify_jwt  &&  authorizationHeader  ==  null )  { 
97+         const  authorizationHeader  =  { 
98+           id : uuidv4 ( ) , 
99+           name : 'Authorization' , 
100+           value : edgeFunctionAuthHeaderVal , 
102101        } 
103-       }  else  { 
104-         const  updatedHttpHeaders  =  httpHeaders . filter ( ( x )  =>  x . name  !==  'Authorization' ) 
102+         setHttpHeaders ( [ ...httpHeaders ,  authorizationHeader ] ) 
103+       }  else  if  ( fn ?. verify_jwt  &&  authorizationHeader ?. value  !==  edgeFunctionAuthHeaderVal )  { 
104+         const  updatedHttpHeaders  =  httpHeaders . map ( ( x )  =>  { 
105+           if  ( x . name  ===  'Authorization' )  return  {  ...x ,  value : edgeFunctionAuthHeaderVal  } 
106+           else  return  x 
107+         } ) 
105108        setHttpHeaders ( updatedHttpHeaders ) 
106109      } 
107-     }  else  { 
108-       const  updatedHttpHeaders  =  httpHeaders . filter ( ( x )  =>  x . name  !==  'Authorization' ) 
109-       setHttpHeaders ( updatedHttpHeaders ) 
110110    } 
111111    // eslint-disable-next-line react-hooks/exhaustive-deps 
112112  } ,  [ values . http_url ,  isSuccessEdgeFunctions ] ) 
0 commit comments