The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix(examples): read new API keys directly from parsed SUPABASE_SECRET_KEYS (#46604)
Tomás Pozoe3be344f5c88
diff --git a/apps/docs/content/guides/ai/examples/huggingface-image-captioning.mdx b/apps/docs/content/guides/ai/examples/huggingface-image-captioning.mdxindex 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 storagediff --git a/apps/docs/content/guides/functions/examples/elevenlabs-transcribe-speech.mdx b/apps/docs/content/guides/functions/examples/elevenlabs-transcribe-speech.mdxindex 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.tsindex 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.storagediff --git a/examples/ai/edge-functions/supabase/functions/generate-embedding/index.ts b/examples/ai/edge-functions/supabase/functions/generate-embedding/index.tsindex 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<Database>(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.tsindex 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<Database>(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.tsindex 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/[email protected]/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<typeof supabase.storage.from>type StorageUploadPromise = ReturnType<StorageFileApi['upload']>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.tsindex 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.tsindex 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:[email protected]'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.tsindex 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 Storagediff --git a/examples/edge-functions/supabase/functions/get-tshirt-competition/index.ts b/examples/edge-functions/supabase/functions/get-tshirt-competition/index.tsindex 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 drawconst { 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.tsindex 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 storagediff --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.tsxindex 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.tsindex 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 Storageconst supabaseClient = createClient(Deno.env.get('SUPABASE_URL') || '',- Deno.env.get(SUPABASE_SECRET_KEYS['default']) || ''+ SUPABASE_SECRET_KEYS['default'] || '')// Create a unique identifier for this generationdiff --git a/examples/edge-functions/supabase/functions/read-storage/index.ts b/examples/edge-functions/supabase/functions/read-storage/index.tsindex 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.tsindex 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.tsindex 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.tsindex 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/[email protected]/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.tsxindex 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.tsindex 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.mdindex 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 Templatesdiff --git a/examples/storage/protomaps/supabase/functions/maps-private/index.ts b/examples/storage/protomaps/supabase/functions/maps-private/index.tsindex 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 headerconst 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.tsindex 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.tsindex 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()