The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
docs(functions): regroup the secrets guide by information type (#50419)
Miranda Limonczenko7012ba4a5539
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.tsindex c0791140edc..3a04aac116a 100644--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts@@ -1783,7 +1783,7 @@ export const functions: NavMenuConstant = {name: 'Configuration',url: undefined,items: [- { name: 'Environment Variables', url: '/guides/functions/secrets' },+ { name: 'Environment variables', url: '/guides/functions/secrets' },{ name: 'Managing Dependencies', url: '/guides/functions/dependencies' },{ name: 'Function Configuration', url: '/guides/functions/function-configuration' },],diff --git a/apps/docs/content/guides/functions/secrets.mdx b/apps/docs/content/guides/functions/secrets.mdxindex ad4fb4e7437..ae432c437a2 100644--- a/apps/docs/content/guides/functions/secrets.mdx+++ b/apps/docs/content/guides/functions/secrets.mdx@@ -1,30 +1,31 @@---id: 'functions-secrets'-title: 'Environment Variables'+title: 'Environment variables'description: 'Managing secrets and environment variables.'subtitle: 'Manage sensitive data securely across environments.'----## Default secrets+Store API keys and other secrets where your Edge Functions can read them. Local development and production load them differently, so set them in both.-Edge Functions have access to these secrets by default:+## Local secrets-- `SUPABASE_URL`: The API gateway for your Supabase project-- `SUPABASE_DB_URL`: The URL for your Postgres database. Use it to connect directly to your database-- `SUPABASE_PUBLISHABLE_KEYS`: The `publishable` keys JSON dictionary for your Supabase API. This is safe to use in a browser when you have Row Level Security enabled-- `SUPABASE_SECRET_KEYS`: The `secret` keys JSON dictionary for your Supabase API. This is safe to use in Edge Functions, but **never** use it in a browser. These keys bypass Row Level Security-- `SUPABASE_JWKS`: The JSON Web Key Set used to verify user JWTs. Same value served at `https://<project-ref>.supabase.co/auth/v1/.well-known/jwks.json`+In development, Edge Functions read secrets from `supabase/functions/.env`, which is automatically loaded on `supabase start`. To use a file you name yourself, such as `.env.local`, pass it to `supabase functions serve` with the `--env-file` option.-Legacy keys:+```bash+supabase functions serve --env-file .env.local+```-- `SUPABASE_ANON_KEY`: The `anon` key for your Supabase API. This is safe to use in a browser when you have Row Level Security enabled-- `SUPABASE_SERVICE_ROLE_KEY`: The `service_role` key for your Supabase API. This is safe to use in Edge Functions, but **never** use it in a browser. This key bypasses Row Level Security+<Admonition type="caution">-In a hosted environment, functions have access to the following environment variables:+A `.env` file committed to Git exposes every secret in it to anyone who can read the repository. Add the file to your `.gitignore` before you commit.-- `SB_REGION`: The region the function was invoked in-- `SB_EXECUTION_ID`: A UUID for the function instance, or [isolate](/docs/guides/functions/architecture#4-execution-mechanics-fast-and-isolated)-- `DENO_DEPLOYMENT_ID`: The version of the function code, formatted as `{project_ref}_{function_id}_{version}`+</Admonition>++Serve the function locally:++```bash+supabase functions serve hello-world+```---@@ -61,42 +62,11 @@ const supabaseAdmin = createClient(----### Local secrets--In development, load environment variables from a file:--- An `.env` file at `supabase/functions/.env`, which is automatically loaded on `supabase start`-- A file you name yourself, such as `.env.local`, passed to `supabase functions serve` with the `--env-file` option--```bash-supabase functions serve --env-file .env.local-```--<Admonition type="caution">--A `.env` file committed to Git exposes every secret in it to anyone who can read the repository. Add the file to your `.gitignore` before you commit.--</Admonition>--Your function reads the secret through Deno's handler:--```tsx-const secretKey = Deno.env.get('STRIPE_SECRET_KEY')-```--Serve the function locally:--```bash-supabase functions serve hello-world-```-------### Production secrets+## Production secretsSet secrets for your production Edge Functions in the Dashboard or with the CLI.-**Using the Dashboard**:+### Using the Dashboard1. Open [Edge Function Secrets](/dashboard/project/_/functions/secrets) in the Dashboard.2. Enter the **Key** and **Value** for your secret, then click **Save**.@@ -113,7 +83,7 @@ Set secrets for your production Edge Functions in the Dashboard or with the CLI.You can paste multiple secrets at once.-**Using the CLI**+### Using the CLICreate a `.env` file with the secrets you want to deploy. Add it to your `.gitignore` before you commit.@@ -145,3 +115,28 @@ supabase secrets listSecrets are available in your functions immediately. You don't need to redeploy after setting them.</Admonition>++Your deployed functions can now read the secret.++---++## Default secrets++Alongside the secrets you set yourself, Edge Functions have access to these by default:++- `SUPABASE_URL`: The API gateway for your Supabase project+- `SUPABASE_DB_URL`: The URL for your Postgres database. Use it to connect directly to your database+- `SUPABASE_PUBLISHABLE_KEYS`: The `publishable` keys JSON dictionary for your Supabase API. This is safe to use in a browser when you have Row Level Security enabled+- `SUPABASE_SECRET_KEYS`: The `secret` keys JSON dictionary for your Supabase API. This is safe to use in Edge Functions, but **never** use it in a browser. These keys bypass Row Level Security+- `SUPABASE_JWKS`: The JSON Web Key Set used to verify user JWTs. Same value served at `https://<project-ref>.supabase.co/auth/v1/.well-known/jwks.json`++Legacy keys:++- `SUPABASE_ANON_KEY`: The `anon` key for your Supabase API. This is safe to use in a browser when you have Row Level Security enabled+- `SUPABASE_SERVICE_ROLE_KEY`: The `service_role` key for your Supabase API. This is safe to use in Edge Functions, but **never** use it in a browser. This key bypasses Row Level Security++In a hosted environment, functions have access to the following environment variables:++- `SB_REGION`: The region the function was invoked in+- `SB_EXECUTION_ID`: A UUID for the function instance, or [isolate](/docs/guides/functions/architecture#4-execution-mechanics-fast-and-isolated)+- `DENO_DEPLOYMENT_ID`: The version of the function code, formatted as `{project_ref}_{function_id}_{version}`diff --git a/apps/docs/content/guides/getting-started/api-keys.mdx b/apps/docs/content/guides/getting-started/api-keys.mdxindex 2b4218f3aa2..211ab9ec5b7 100644--- a/apps/docs/content/guides/getting-started/api-keys.mdx+++ b/apps/docs/content/guides/getting-started/api-keys.mdx@@ -274,7 +274,7 @@ const secretKeys = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)const supabaseAdmin = createClient(Deno.env.get('SUPABASE_URL')!, secretKeys['default'])```-`SUPABASE_ANON_KEY` and `SUPABASE_SERVICE_ROLE_KEY` still exist in the runtime, but they carry the legacy keys, so reading them keeps you on the deprecated path. See [Environment Variables](/docs/guides/functions/secrets) for the full list of injected variables.+`SUPABASE_ANON_KEY` and `SUPABASE_SERVICE_ROLE_KEY` still exist in the runtime, but they carry the legacy keys, so reading them keeps you on the deprecated path. See [Environment variables](/docs/guides/functions/secrets) for the full list of injected variables.If you are replacing legacy keys in an existing application rather than starting fresh, follow [Migrating to new API keys](/docs/guides/getting-started/migrating-to-new-api-keys).diff --git a/apps/docs/content/guides/getting-started/migrating-to-new-api-keys.mdx b/apps/docs/content/guides/getting-started/migrating-to-new-api-keys.mdxindex 66bec46fce7..2d4b0192cd4 100644--- a/apps/docs/content/guides/getting-started/migrating-to-new-api-keys.mdx+++ b/apps/docs/content/guides/getting-started/migrating-to-new-api-keys.mdx@@ -122,7 +122,7 @@ const secretKey = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!const secretKey = JSON.parse(Deno.env.get('SUPABASE_SECRET_KEYS')!)['default']```-The publishable keys work the same way through `SUPABASE_PUBLISHABLE_KEYS`. Read [the Managing Secrets guide](/docs/guides/functions/secrets) for more on environment variables in Edge Functions.+The publishable keys work the same way through `SUPABASE_PUBLISHABLE_KEYS`. Read [Environment variables](/docs/guides/functions/secrets) for more on environment variables in Edge Functions.If you created more than one secret key in [step 1](#step-1-create-the-new-api-keys), every key lives in the same `SUPABASE_SECRET_KEYS` object, each under its own name. Read a non-default key the same way:diff --git a/apps/docs/content/troubleshooting/working-around-the-edge-function-secrets-limit.mdx b/apps/docs/content/troubleshooting/working-around-the-edge-function-secrets-limit.mdxindex 818064d9a2c..88f4841f520 100644--- a/apps/docs/content/troubleshooting/working-around-the-edge-function-secrets-limit.mdx+++ b/apps/docs/content/troubleshooting/working-around-the-edge-function-secrets-limit.mdx@@ -34,7 +34,7 @@ Supabase doesn't raise this limit on a per-project basis today. The workaround b3. Confirm it was set with `supabase secrets list`.-This is the same pattern Supabase's own default secrets use — `SUPABASE_PUBLISHABLE_KEYS` and `SUPABASE_SECRET_KEYS` are themselves JSON dictionaries parsed the same way (see [Environment Variables](/docs/guides/functions/secrets#accessing-environment-variables)).+This is the same pattern Supabase's own default secrets use — `SUPABASE_PUBLISHABLE_KEYS` and `SUPABASE_SECRET_KEYS` are themselves JSON dictionaries parsed the same way (see [Environment variables](/docs/guides/functions/secrets#accessing-environment-variables)).### Things to watch for@@ -56,5 +56,5 @@ For a flat list of project-wide credentials, [grouping them into a single JSON s## Additional resources- [Functions limits — Secrets](/docs/guides/functions/limits#secrets)-- [Environment Variables — accessing and setting secrets](/docs/guides/functions/secrets)+- [Environment variables — accessing and setting secrets](/docs/guides/functions/secrets)- [Supabase Vault](/docs/guides/database/vault)