examples/edge-functions/README.md
Supabase Edge Functions are written in TypeScript, run via Deno, and deployed with the Supabase CLI. Please download the latest version of the Supabase CLI, or upgrade it if you have it already installed.
We're constantly adding new Function Examples, check our docs for a complete list!
supabase start (make sure your Docker daemon is running.)cp ./supabase/.env.local.example ./supabase/.env.local to create your local .env file..env.local file.supabase functions serve --env-file ./supabase/.env.local --no-verify-jwtThis example includes a create-react-app in the ./app/ directory which you can use as a sort of postman to make test requests both locally and to your deployed functions.
cd appnpm installnpm startNote: when testing locally, the select dropdown doesn't have any effect, and invoke simply calls whatever function is currently served by the CLI.
Generate access token and log in to CLI
supabase loginLink your project
supabase link --project-ref your-project-refSet up your secrets
supabase secrets set --env-file ./supabase/.env.local to set the environment variables.(This is assuming your local and production secrets are the same. The recommended way is to create a separate .env file for storing production secrets, and then use it to set the environment variables while deploying.)
supabase secrets list to check that it worked and also to see what other env vars are set by default.Deploy the function
supabase functions deploy your-function-nameIn your ./app/.env file remove the SUPA_FUNCTION_LOCALHOST variable and restart your Expo app.
This example includes a create-react-app in the ./app/ directory which you can use as a sort of postman to make test requests both locally and to your deployed functions.
cd appcp .env.example .envnpm installnpm startThis example includes a deploy GitHub Action that automatically deploys your Supabase Edge Functions when pushing to or merging into the main branch.
You can use the setup-cli GitHub Action to run Supabase CLI commands in your GitHub Actions, for example to deploy a Supabase Edge Function:
name: Deploy Function
on:
push:
branches:
- main
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
env:
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
PROJECT_ID: your-project-id
steps:
- uses: actions/checkout@v3
- uses: supabase/setup-cli@v1
with:
version: latest
- run: supabase functions deploy --project-ref $PROJECT_ID
Since Supabase CLI v1.62.0 you can deploy all functions with a single command.
Individual function configuration like JWT verification and import map location can be set via the config.toml file.
[functions.hello-world]
verify_jwt = false
\o/ That's it, you can now invoke your Supabase Function via the supabase-js and supabase-dart client libraries. (More client libraries coming soon. Check the supabase-community org for details).
For more info on Supabase Functions, check out the docs and the examples.