Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Hide auth header from invoke command if enforce jwt is not true (#33209)

Joshen Lim7dc467d843ae
diff --git a/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.tsx b/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.tsx
index f68dfc3b8ae..11f6df3e22c 100644
--- a/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.tsx
+++ b/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.tsx
@@ -63,11 +63,11 @@ const EdgeFunctionDetails = () => {
? `https://${customDomainData.customDomain.hostname}/functions/v1/${selectedFunction?.slug}`
: `${protocol}://${endpoint}/functions/v1/${selectedFunction?.slug}`
- const { managementCommands, secretCommands, invokeCommands } = generateCLICommands(
+ const { managementCommands, secretCommands, invokeCommands } = generateCLICommands({
selectedFunction,
functionUrl,
- apiKey
- )
+ anonKey: apiKey,
+ })
const onUpdateFunction = async (values: any, { resetForm }: any) => {
if (!projectRef) return console.error('Project ref is required')
diff --git a/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.utils.tsx b/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.utils.tsx
index e8ec2079990..f83befe18a2 100644
--- a/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.utils.tsx
+++ b/apps/studio/components/interfaces/Functions/EdgeFunctionDetails/EdgeFunctionDetails.utils.tsx
@@ -1,8 +1,14 @@
-export const generateCLICommands = (
- selectedFunction: any,
- functionUrl: string,
+import { EdgeFunction } from 'data/edge-functions/edge-function-query'
+
+export const generateCLICommands = ({
+ selectedFunction,
+ functionUrl,
+ anonKey,
+}: {
+ selectedFunction?: EdgeFunction
+ functionUrl: string
anonKey: string
-) => {
+}) => {
const managementCommands: any = [
{
command: `supabase functions deploy ${selectedFunction?.slug}`,
@@ -80,8 +86,12 @@ export const generateCLICommands = (
jsx: () => {
return (
<>
- <span className="text-brand-600">curl</span> -L -X POST '{functionUrl}' -H
- 'Authorization: Bearer [YOUR ANON KEY]' {`--data '{"name":"Functions"}'`}
+ <span className="text-brand-600">curl</span> -L -X POST '{functionUrl}'{' '}
+ {selectedFunction?.verify_jwt
+ ? `-H
+ 'Authorization: Bearer [YOUR ANON KEY]' `
+ : ''}
+ {`--data '{"name":"Functions"}'`}
</>
)
},
diff --git a/apps/studio/data/edge-functions/edge-function-query.ts b/apps/studio/data/edge-functions/edge-function-query.ts
index 63f1b03470b..ad6f54dee2a 100644
--- a/apps/studio/data/edge-functions/edge-function-query.ts
+++ b/apps/studio/data/edge-functions/edge-function-query.ts
@@ -1,4 +1,5 @@
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
+import { components } from 'api-types'
import { get, handleError } from 'data/fetchers'
import { IS_PLATFORM } from 'lib/constants'
import { edgeFunctionsKeys } from './keys'
@@ -8,6 +9,8 @@ export type EdgeFunctionVariables = {
slug?: string
}
+export type EdgeFunction = components['schemas']['FunctionSlugResponse']
+
export async function getEdgeFunction(
{ projectRef, slug }: EdgeFunctionVariables,
signal?: AbortSignal