diff --git a/apps/docs/content/guides/ai/examples/huggingface-image-captioning.mdx b/apps/docs/content/guides/ai/examples/huggingface-image-captioning.mdx index b6b7b05ea47..a0f89695d59 100644 --- a/apps/docs/content/guides/ai/examples/huggingface-image-captioning.mdx +++ b/apps/docs/content/guides/ai/examples/huggingface-image-captioning.mdx @@ -65,7 +65,7 @@ Deno.serve(async (req) => { // Supabase API URL - env var exported by default when deployed. Deno.env.get('SUPABASE_URL') ?? '', // Supabase API SECRET KEY - env var exported by default when deployed. - Deno.env.get(SUPABASE_SECRET_KEYS['default']) ?? '' + SUPABASE_SECRET_KEYS['default'] ?? '' ) // Construct image url from storage diff --git a/apps/docs/content/guides/functions/examples/elevenlabs-transcribe-speech.mdx b/apps/docs/content/guides/functions/examples/elevenlabs-transcribe-speech.mdx index db8248876c3..6cdc51f58ca 100644 --- a/apps/docs/content/guides/functions/examples/elevenlabs-transcribe-speech.mdx +++ b/apps/docs/content/guides/functions/examples/elevenlabs-transcribe-speech.mdx @@ -120,7 +120,7 @@ const elevenLabsClient = new ElevenLabsClient({ const SUPABASE_SECRET_KEYS = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!) const supabase = createClient( Deno.env.get('SUPABASE_URL') || '', - Deno.env.get(SUPABASE_SECRET_KEYS['default']) || '' + SUPABASE_SECRET_KEYS['default'] || '' ) async function scribe({ diff --git a/examples/ai/aws_bedrock_image_gen/supabase/functions/image_gen/index.ts b/examples/ai/aws_bedrock_image_gen/supabase/functions/image_gen/index.ts index 5e7ffc82034..e20b971cfd5 100644 --- a/examples/ai/aws_bedrock_image_gen/supabase/functions/image_gen/index.ts +++ b/examples/ai/aws_bedrock_image_gen/supabase/functions/image_gen/index.ts @@ -58,7 +58,7 @@ Deno.serve(async (req) => { // Supabase API URL - env var exported by default. Deno.env.get('SUPABASE_URL')!, // Supabase API SECRET KEY - env var exported by default. - Deno.env.get(SUPABASE_SECRET_KEYS['default'])! + SUPABASE_SECRET_KEYS['default']! ) const { data: upload, error: uploadError } = await supabaseClient.storage diff --git a/examples/ai/edge-functions/supabase/functions/generate-embedding/index.ts b/examples/ai/edge-functions/supabase/functions/generate-embedding/index.ts index 43143fbcab4..034bed58306 100644 --- a/examples/ai/edge-functions/supabase/functions/generate-embedding/index.ts +++ b/examples/ai/edge-functions/supabase/functions/generate-embedding/index.ts @@ -15,7 +15,7 @@ const SUPABASE_SECRET_KEYS = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!) const supabase = createClient( Deno.env.get('SUPABASE_URL')!, - Deno.env.get(SUPABASE_SECRET_KEYS['default'])! + SUPABASE_SECRET_KEYS['default']! ) const model = new Supabase.ai.Session('gte-small') diff --git a/examples/ai/edge-functions/supabase/functions/search/index.ts b/examples/ai/edge-functions/supabase/functions/search/index.ts index bd003be2f3b..2497e88b4fa 100644 --- a/examples/ai/edge-functions/supabase/functions/search/index.ts +++ b/examples/ai/edge-functions/supabase/functions/search/index.ts @@ -7,7 +7,7 @@ const SUPABASE_SECRET_KEYS = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!) const supabase = createClient( Deno.env.get('SUPABASE_URL')!, - Deno.env.get(SUPABASE_SECRET_KEYS['default'])! + SUPABASE_SECRET_KEYS['default']! ) const model = new Supabase.ai.Session('gte-small') diff --git a/examples/edge-functions/supabase/functions/background-upload-storage/index.ts b/examples/edge-functions/supabase/functions/background-upload-storage/index.ts index 49d5d9a99c7..49fdb1ea55c 100644 --- a/examples/edge-functions/supabase/functions/background-upload-storage/index.ts +++ b/examples/edge-functions/supabase/functions/background-upload-storage/index.ts @@ -4,10 +4,7 @@ import OpenAI from 'https://deno.land/x/openai@v4.68.2/mod.ts' const client = new OpenAI({ apiKey: Deno.env.get('OPENAI_API_KEY')! }) const SUPABASE_SECRET_KEYS = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!) -const supabase = createClient( - Deno.env.get('SUPABASE_URL')!, - Deno.env.get(SUPABASE_SECRET_KEYS['default'])! -) +const supabase = createClient(Deno.env.get('SUPABASE_URL')!, SUPABASE_SECRET_KEYS['default']!) type StorageFileApi = ReturnType type StorageUploadPromise = ReturnType diff --git a/examples/edge-functions/supabase/functions/elevenlabs-speech-to-text/index.ts b/examples/edge-functions/supabase/functions/elevenlabs-speech-to-text/index.ts index 6623cb3b5e4..56905387d63 100644 --- a/examples/edge-functions/supabase/functions/elevenlabs-speech-to-text/index.ts +++ b/examples/edge-functions/supabase/functions/elevenlabs-speech-to-text/index.ts @@ -19,7 +19,7 @@ const SUPABASE_SECRET_KEYS = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!) const supabase = createClient( Deno.env.get('SUPABASE_URL') || '', - Deno.env.get(SUPABASE_SECRET_KEYS['default']) || '' + SUPABASE_SECRET_KEYS['default'] || '' ) async function scribe({ diff --git a/examples/edge-functions/supabase/functions/elevenlabs-text-to-speech/index.ts b/examples/edge-functions/supabase/functions/elevenlabs-text-to-speech/index.ts index 972e449ef8b..b142f0b0f10 100644 --- a/examples/edge-functions/supabase/functions/elevenlabs-text-to-speech/index.ts +++ b/examples/edge-functions/supabase/functions/elevenlabs-text-to-speech/index.ts @@ -5,10 +5,7 @@ import { ElevenLabsClient } from 'npm:elevenlabs@1.52.0' import * as hash from 'npm:object-hash' const SUPABASE_SECRET_KEYS = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!) -const supabase = createClient( - Deno.env.get('SUPABASE_URL')!, - Deno.env.get(SUPABASE_SECRET_KEYS['default'])! -) +const supabase = createClient(Deno.env.get('SUPABASE_URL')!, SUPABASE_SECRET_KEYS['default']!) const client = new ElevenLabsClient({ apiKey: Deno.env.get('ELEVENLABS_API_KEY'), diff --git a/examples/edge-functions/supabase/functions/file-upload-storage/index.ts b/examples/edge-functions/supabase/functions/file-upload-storage/index.ts index 37dee7427f9..80bef78d864 100644 --- a/examples/edge-functions/supabase/functions/file-upload-storage/index.ts +++ b/examples/edge-functions/supabase/functions/file-upload-storage/index.ts @@ -29,7 +29,7 @@ app.use(async (ctx) => { // Supabase API URL - env var exported by default. Deno.env.get('SUPABASE_URL')!, // Supabase publishable key - env var exported by default. - Deno.env.get(SUPABASE_PUBLISHABLE_KEYS['default'])! + SUPABASE_PUBLISHABLE_KEYS['default']! ) //upload image to Storage diff --git a/examples/edge-functions/supabase/functions/get-tshirt-competition/index.ts b/examples/edge-functions/supabase/functions/get-tshirt-competition/index.ts index de5dc1c2b02..20e8f0d4f5d 100644 --- a/examples/edge-functions/supabase/functions/get-tshirt-competition/index.ts +++ b/examples/edge-functions/supabase/functions/get-tshirt-competition/index.ts @@ -61,7 +61,7 @@ Deno.serve(async (req) => { // Supabase API URL - env var exported by default when deployed. Deno.env.get('SUPABASE_URL') ?? '', // Supabase API SECRET KEY - env var exported by default when deployed. - Deno.env.get(SUPABASE_SECRET_KEYS['default']) ?? '' + SUPABASE_SECRET_KEYS['default'] ?? '' ) // Submit email to draw const { error } = await supabaseAdminClient.from('get-tshirt-competition-2').upsert( diff --git a/examples/edge-functions/supabase/functions/huggingface-image-captioning/index.ts b/examples/edge-functions/supabase/functions/huggingface-image-captioning/index.ts index 15455577c2b..790ee619019 100644 --- a/examples/edge-functions/supabase/functions/huggingface-image-captioning/index.ts +++ b/examples/edge-functions/supabase/functions/huggingface-image-captioning/index.ts @@ -23,7 +23,7 @@ Deno.serve(async (req) => { // Supabase API URL - env var exported by default when deployed. Deno.env.get('SUPABASE_URL') ?? '', // Supabase API SECRET KEY - env var exported by default when deployed. - Deno.env.get(SUPABASE_SECRET_KEYS['default']) ?? '' + SUPABASE_SECRET_KEYS['default'] ?? '' ) // Construct image url from storage diff --git a/examples/edge-functions/supabase/functions/og-image-with-storage-cdn/handler.tsx b/examples/edge-functions/supabase/functions/og-image-with-storage-cdn/handler.tsx index 3cea004a04c..1252b04c072 100644 --- a/examples/edge-functions/supabase/functions/og-image-with-storage-cdn/handler.tsx +++ b/examples/edge-functions/supabase/functions/og-image-with-storage-cdn/handler.tsx @@ -201,7 +201,7 @@ export async function handler(req: Request) { // Supabase API URL - env var exported by default when deployed. Deno.env.get('SUPABASE_URL') ?? '', // Supabase API SECRET KEY - env var exported by default when deployed. - Deno.env.get(SUPABASE_SECRET_KEYS['default']) ?? '' + SUPABASE_SECRET_KEYS['default'] ?? '' ) // Upload image to storage. diff --git a/examples/edge-functions/supabase/functions/openai-image-generation/index.ts b/examples/edge-functions/supabase/functions/openai-image-generation/index.ts index 8117c2edf72..0c5f46aaa3f 100644 --- a/examples/edge-functions/supabase/functions/openai-image-generation/index.ts +++ b/examples/edge-functions/supabase/functions/openai-image-generation/index.ts @@ -85,7 +85,7 @@ Deno.serve(async (req) => { // Upload the generated image to Supabase Storage const supabaseClient = createClient( Deno.env.get('SUPABASE_URL') || '', - Deno.env.get(SUPABASE_SECRET_KEYS['default']) || '' + SUPABASE_SECRET_KEYS['default'] || '' ) // Create a unique identifier for this generation diff --git a/examples/edge-functions/supabase/functions/read-storage/index.ts b/examples/edge-functions/supabase/functions/read-storage/index.ts index 443bf721a15..d0063546b70 100644 --- a/examples/edge-functions/supabase/functions/read-storage/index.ts +++ b/examples/edge-functions/supabase/functions/read-storage/index.ts @@ -25,7 +25,7 @@ Deno.serve(async (req) => { // Supabase API URL - env var exported by default. Deno.env.get('SUPABASE_URL') ?? '', // Supabase API publishable key - env var exported by default. - Deno.env.get(SUPABASE_PUBLISHABLE_KEYS['default']) ?? '', + SUPABASE_PUBLISHABLE_KEYS['default'] ?? '', // Create client with Auth context of the user that called the function. // This way your row-level-security (RLS) policies are applied. { diff --git a/examples/edge-functions/supabase/functions/restful-tasks/index.ts b/examples/edge-functions/supabase/functions/restful-tasks/index.ts index 2182334fc6a..0b4527abde8 100644 --- a/examples/edge-functions/supabase/functions/restful-tasks/index.ts +++ b/examples/edge-functions/supabase/functions/restful-tasks/index.ts @@ -82,7 +82,7 @@ Deno.serve(async (req) => { // Supabase API URL - env var exported by default. Deno.env.get('SUPABASE_URL') ?? '', // Supabase publishable key - env var exported by default. - Deno.env.get(SUPABASE_PUBLISHABLE_KEYS['default']) ?? '', + SUPABASE_PUBLISHABLE_KEYS['default'] ?? '', // Create client with Auth context of the user that called the function. // This way your row-level-security (RLS) policies are applied. { diff --git a/examples/edge-functions/supabase/functions/select-from-table-with-auth-rls/index.ts b/examples/edge-functions/supabase/functions/select-from-table-with-auth-rls/index.ts index a9badc940b1..c0c1e62b03c 100644 --- a/examples/edge-functions/supabase/functions/select-from-table-with-auth-rls/index.ts +++ b/examples/edge-functions/supabase/functions/select-from-table-with-auth-rls/index.ts @@ -23,7 +23,7 @@ Deno.serve(async (req: Request) => { // Supabase API URL - env var exported by default. Deno.env.get('SUPABASE_URL') ?? '', // Supabase API PUBLISHABLE KEY - env var exported by default. - Deno.env.get(SUPABASE_PUBLISHABLE_KEYS['default']) ?? '', + SUPABASE_PUBLISHABLE_KEYS['default'] ?? '', // Create client with Auth context of the user that called the function. // This way your row-level-security (RLS) policies are applied. { diff --git a/examples/edge-functions/supabase/functions/sentry/index.ts b/examples/edge-functions/supabase/functions/sentry/index.ts index abdddd9b97d..23a04024a92 100644 --- a/examples/edge-functions/supabase/functions/sentry/index.ts +++ b/examples/edge-functions/supabase/functions/sentry/index.ts @@ -9,10 +9,7 @@ import * as Sentry from 'https://deno.land/x/sentry@7.102.0/index.mjs' const SUPABASE_SECRET_KEYS = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!) -const supabase = createClient( - Deno.env.get('SUPABASE_URL')!, - Deno.env.get(SUPABASE_SECRET_KEYS['default'])! -) +const supabase = createClient(Deno.env.get('SUPABASE_URL')!, SUPABASE_SECRET_KEYS['default']!) Sentry.init({ dsn: Deno.env.get('SENTRY_DSN'), diff --git a/examples/edge-functions/supabase/functions/tweet-to-image/handler.tsx b/examples/edge-functions/supabase/functions/tweet-to-image/handler.tsx index ddd9c340c2b..00e16086f49 100644 --- a/examples/edge-functions/supabase/functions/tweet-to-image/handler.tsx +++ b/examples/edge-functions/supabase/functions/tweet-to-image/handler.tsx @@ -70,7 +70,7 @@ export async function handler(req: Request) { // Supabase API URL - env var exported by default when deployed. Deno.env.get('SUPABASE_URL') ?? '', // Supabase API SECRET KEY - env var exported by default when deployed. - Deno.env.get(SUPABASE_SECRET_KEYS['default']) ?? '' + SUPABASE_SECRET_KEYS['default'] ?? '' ) // Upload image to storage. diff --git a/examples/edge-functions/supabase/functions/upstash-redis-ratelimit/index.ts b/examples/edge-functions/supabase/functions/upstash-redis-ratelimit/index.ts index ef5727c3b22..0c8a05e10de 100644 --- a/examples/edge-functions/supabase/functions/upstash-redis-ratelimit/index.ts +++ b/examples/edge-functions/supabase/functions/upstash-redis-ratelimit/index.ts @@ -12,7 +12,7 @@ Deno.serve(async (req) => { // Supabase API URL - env var exported by default. Deno.env.get('SUPABASE_URL') ?? '', // Supabase publishable key - env var exported by default. - Deno.env.get(SUPABASE_PUBLISHABLE_KEYS['default']) ?? '', + SUPABASE_PUBLISHABLE_KEYS['default'] ?? '', // Create client with Auth context of the user that called the function. // This way your row-level-security (RLS) policies are applied. { diff --git a/examples/prompts/edge-functions.md b/examples/prompts/edge-functions.md index ba48db3fa8e..87447d7a997 100644 --- a/examples/prompts/edge-functions.md +++ b/examples/prompts/edge-functions.md @@ -23,7 +23,7 @@ You're an expert in writing TypeScript and Deno JavaScript runtime. Generate **h - SUPABASE_SECRET_KEYS - SUPABASE_DB_URL -You then need to use `JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)` or `JSON.parse(Deno.env.get('SUPABASE_PUBLISHABLE_KEYS')!)` to access the actual keys in the code. For example, `Deno.env.get(SUPABASE_SECRET_KEYS['default'])` to access the default service key. 9. To set other environment variables (ie. secrets) users can put them in a env file and run the `supabase secrets set --env-file path/to/env-file` 10. A single Edge Function can handle multiple routes. It is recommended to use a library like Express or Hono to handle the routes as it's easier for developer to understand and maintain. Each route must be prefixed with `/function-name` so they are routed correctly. 11. File write operations are ONLY permitted on `/tmp` directory. You can use either Deno or Node File APIs. 12. Use `EdgeRuntime.waitUntil(promise)` static method to run long-running tasks in the background without blocking response to a request. Do NOT assume it is available in the request / execution context. +You then need to parse them with `JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)` or `JSON.parse(Deno.env.get('SUPABASE_PUBLISHABLE_KEYS')!)` to access the actual keys in the code. For example, assign the parsed map first with `const SUPABASE_SECRET_KEYS = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)` and then index it with `SUPABASE_SECRET_KEYS['default']` to access the default secret key. 9. To set other environment variables (ie. secrets) users can put them in a env file and run the `supabase secrets set --env-file path/to/env-file` 10. A single Edge Function can handle multiple routes. It is recommended to use a library like Express or Hono to handle the routes as it's easier for developer to understand and maintain. Each route must be prefixed with `/function-name` so they are routed correctly. 11. File write operations are ONLY permitted on `/tmp` directory. You can use either Deno or Node File APIs. 12. Use `EdgeRuntime.waitUntil(promise)` static method to run long-running tasks in the background without blocking response to a request. Do NOT assume it is available in the request / execution context. ## Example Templates diff --git a/examples/storage/protomaps/supabase/functions/maps-private/index.ts b/examples/storage/protomaps/supabase/functions/maps-private/index.ts index cacfc61de02..d0187cdafab 100644 --- a/examples/storage/protomaps/supabase/functions/maps-private/index.ts +++ b/examples/storage/protomaps/supabase/functions/maps-private/index.ts @@ -27,6 +27,6 @@ Deno.serve((req) => { const { method, headers } = req // Add Auth header const modHeaders = new Headers(headers) - modHeaders.append('authorization', `Bearer ${Deno.env.get(SUPABASE_SECRET_KEYS['default'])!}`) + modHeaders.append('authorization', `Bearer ${SUPABASE_SECRET_KEYS['default']!}`) return fetch(url, { method, headers: modHeaders }) }) diff --git a/examples/storage/resumable-upload-signed-uppy/supabase/functions/create-upload-token/index.ts b/examples/storage/resumable-upload-signed-uppy/supabase/functions/create-upload-token/index.ts index 2d1fb040fed..b61f9fafc6b 100644 --- a/examples/storage/resumable-upload-signed-uppy/supabase/functions/create-upload-token/index.ts +++ b/examples/storage/resumable-upload-signed-uppy/supabase/functions/create-upload-token/index.ts @@ -5,7 +5,7 @@ const SUPABASE_SECRET_KEYS = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!) Deno.serve(async (req) => { const SUPABASE_URL = Deno.env.get('SUPABASE_URL') ?? '' - const SUPABASE_SECRET_KEY = Deno.env.get(SUPABASE_SECRET_KEYS['default']) ?? '' + const SUPABASE_SECRET_KEY = SUPABASE_SECRET_KEYS['default'] ?? '' const supabase = createClient(SUPABASE_URL, SUPABASE_SECRET_KEY) diff --git a/examples/user-management/expo-push-notifications/supabase/functions/push/index.ts b/examples/user-management/expo-push-notifications/supabase/functions/push/index.ts index 7f73cb91ded..76ea8f56338 100644 --- a/examples/user-management/expo-push-notifications/supabase/functions/push/index.ts +++ b/examples/user-management/expo-push-notifications/supabase/functions/push/index.ts @@ -20,10 +20,7 @@ interface WebhookPayload { } const SUPABASE_SECRET_KEYS = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!) -const supabase = createClient( - Deno.env.get('SUPABASE_URL')!, - Deno.env.get(SUPABASE_SECRET_KEYS['default'])! -) +const supabase = createClient(Deno.env.get('SUPABASE_URL')!, SUPABASE_SECRET_KEYS['default']!) Deno.serve(async (req) => { const payload: WebhookPayload = await req.json()