Skip to Content
Edge FunctionsLocal Development

Local development

You can run the edge functions on your machine against a local Supabase stack, which avoids a redeploy for every change.

Prerequisites

Install the Supabase CLI and a Docker-compatible container runtime . Run these commands from the app’s root directory.

Start the local stack

supabase start

This starts Postgres, Auth, Storage and Studio and prints the local connection details. Keep the local anon key for the app configuration below.

Apply the migrations

supabase migration up --local

This applies pending migrations without resetting your local data.

Set the function secrets

Create supabase/functions/.env with the custom secrets you need:

supabase/functions/.env
OPENROUTER_API_KEY="<your-openrouter-key>" REVENUECAT_SECRET_KEY="<your-revenuecat-v1-secret-key>" PRO_ENTITLEMENT_ID="pro" AI_FREE_MESSAGES="10"

The local runtime supplies the SUPABASE_* connection settings. Keep this file for custom secrets. Match the entitlement and allowance to the app’s configuration, and omit the RevenueCat key if you are only testing free features. See function secrets.

This file is gitignored. Keep real secret values out of committed files.

Serve the functions

supabase functions serve --env-file supabase/functions/.env

The host endpoints are http://127.0.0.1:54321/functions/v1/<name>. Keep this terminal open for function output. Restart the command after changing secrets.

Point the app at your local stack

In .env.local:

.env.local
EXPO_PUBLIC_SUPABASE_URL="http://127.0.0.1:54321" EXPO_PUBLIC_SUPABASE_ANON_KEY="<anon key from supabase start>"

Use 127.0.0.1 for the iOS Simulator on the same Mac. For an Android Emulator, use 10.0.2.2, its address for the host machine . On a physical device, use your machine’s LAN IP and connect both devices to the same network.

Restart the development server and reload the app. Create or sign in to a local test account; hosted users and sessions do not transfer to the local stack.

Verify

Send a chat message and check that the reply streams back. Reopen the thread to confirm it was saved. Use local Studio to inspect the rows and the function terminal to investigate errors.

Restore your hosted app settings when you finish testing locally, then restart the development server and sign in again.

Regenerating database types

After applying a local migration, generate types from the local database:

supabase gen types --lang=typescript --local --schema public > src/lib/db/database.types.ts

See type definitions for generating from a hosted project.

Last updated on