# Edge functions (/build/connectors/supabase/edge-functions)

<LlmsDirective />

<Info>
  Rocket auto-detects when backend logic is needed and generates Supabase Edge Functions for you. This guide covers creating and deploying functions from chat, managing secrets, and troubleshooting deployment errors.
</Info>

## What are Supabase Edge Functions? [#what-are-supabase-edge-functions]

Edge Functions run on Supabase infrastructure and handle secure backend logic for your app.
They are ideal for tasks like sending emails, calling APIs, generating PDFs, or processing data.

- Execute on the server, not the user's device.
- Can store and use secrets securely.
- Can be triggered from your UI or backend processes.

<Info>
  <b>Why use Edge Functions with Rocket?</b>
  Rocket writes the function code, prompts you for secrets, and deploys to Supabase. All from chat.
</Info>

## Create or detect a function in Rocket [#create-or-detect-a-function-in-rocket]

Rocket auto-checks if backend logic is needed when you build features.
If a function is required and does not exist, Rocket generates it and opens a chat popup.

You will see:
- The function name and a code preview.
- Input fields for any required secrets.
- A **Push to Supabase** button to deploy.

You can also ask Rocket to create a function manually. For example:

```plaintext wrap
Create an Edge Function that sends a welcome email with Resend when a user signs up.
```

Rocket will:
- Write the function code.
- Prompt for the `RESEND_API_KEY`.

<Frame caption="Resend secret prompt during Edge Function creation">
  <img src="/images/build/connectors/supabase/edge-functions/supabase-resend-API-light.webp" alt="Popup showing secure input field for Resend API key during function creation." className="theme-image light-image" />
  <img src="/images/build/connectors/supabase/edge-functions/supabase-resend-API-dark.webp" alt="Popup showing secure input field for Resend API key during function creation." className="theme-image dark-image" />
</Frame>

- Show a **Push to Supabase** popup so you can deploy the function.

<Frame caption="Deploy Edge Function from Rocket">
  <img src="/images/build/connectors/supabase/edge-functions/edge-function-popup-light.webp" alt="Edge Function deployment popup with code preview, secret fields, and deploy button." className="theme-image light-image" />
  <img src="/images/build/connectors/supabase/edge-functions/edge-function-popup-dark.webp" alt="Edge Function deployment popup with code preview, secret fields, and deploy button." className="theme-image dark-image" />
</Frame>

<Note>
  You can stay in Rocket for most workflows. Open the Supabase dashboard when you want to review a deployed function, check logs, or [manage secrets](#manage-secrets) manually.
</Note>

## View deployed functions in Supabase [#view-deployed-functions-in-supabase]

After you push a function, you can confirm it in the Supabase dashboard.

1. Go to the [Supabase Dashboard](https://supabase.com/dashboard) and open your project.
2. Click **Edge Functions** in the left sidebar.

<Frame caption="Supabase: list of deployed Edge Functions">
  <img src="/images/build/connectors/supabase/edge-functions/supabase-edge-function-light.webp" alt="Supabase dashboard showing a list of deployed Edge Functions." className="theme-image light-image" />
  <img src="/images/build/connectors/supabase/edge-functions/supabase-edge-function-dark.webp" alt="Supabase dashboard showing a list of deployed Edge Functions." className="theme-image dark-image" />
</Frame>

Open a function to see its details, code, and logs.

<Frame caption="Supabase: deployed Edge Function details">
  <img src="/images/build/connectors/supabase/edge-functions/edge-function-supabase-light.webp" alt="Supabase dashboard showing Edge Function details and status." className="theme-image light-image" />
  <img src="/images/build/connectors/supabase/edge-functions/edge-function-supabase-dark.webp" alt="Supabase dashboard showing Edge Function details and status." className="theme-image dark-image" />
</Frame>

## Manage secrets [#manage-secrets]

Secrets such as `RESEND_API_KEY` or `STRIPE_SECRET_KEY` are stored in Supabase, not in Rocket. Your Edge Functions read them at runtime.

### Add secrets from Rocket [#add-secrets-from-rocket]

When Rocket asks for secrets:
- Paste them into the secure input fields provided.
- Rocket saves them to your Supabase project during deploy.
- To rotate a value later, ask Rocket to redeploy with the new key, or [update it manually in Supabase](#update-a-secret-manually-in-supabase).

### View secrets in Supabase [#view-secrets-in-supabase]

1. Go to the [Supabase Dashboard](https://supabase.com/dashboard) and open your project.
2. In the left sidebar, open **Edge Functions**, then open **Secrets**.

<Frame caption="Supabase: stored secrets for Edge Functions">
  <img src="/images/build/connectors/supabase/edge-functions/supabase-secrets-function-light.webp" alt="Supabase dashboard displaying secrets linked to Edge Functions." className="theme-image light-image" />
  <img src="/images/build/connectors/supabase/edge-functions/supabase-secrets-function-dark.webp" alt="Supabase dashboard displaying secrets linked to Edge Functions." className="theme-image dark-image" />
</Frame>

### Update a secret manually in Supabase [#update-a-secret-manually-in-supabase]

If Rocket cannot update a secret, change it in the Supabase dashboard. Use this when the secure popup fails, or when an Edge Function errors after you rotate a [Stripe](/build/connectors/stripe), [Resend](/build/connectors/resend), or [Twilio](/build/connectors/twilio) key.

<Steps>

  <Step title="Open Edge Function secrets">
    1. Go to the [Supabase Dashboard](https://supabase.com/dashboard) and open your project.
    2. In the left sidebar, open **Edge Functions**, then open **Secrets**.
  </Step>

  <Step title="Replace the secret value">
    1. Find the secret name your function uses (see the table below).
    2. Enter the new key or token as the value. If the name already exists, Supabase replaces the previous value.
    3. Click **Save**.

    Deployed functions pick up the new value immediately. You do not need to redeploy the function.
  </Step>

  <Step title="Confirm the function works">
    Trigger the flow again in your Rocket app. For example, send a test email, create a checkout, or send an SMS. If it still fails, check the function **Logs** tab in Supabase for the exact error.
  </Step>

</Steps>

Common secret names Rocket uses with connectors:

| Connector | Typical secret name |
|:----------|:--------------------|
| Stripe | `STRIPE_SECRET_KEY` |
| Resend | `RESEND_API_KEY` |
| Twilio | `TWILIO_AUTH_TOKEN` (and often `TWILIO_ACCOUNT_SID`) |

<Note>
  Updating the connector in Rocket with **Edit** on the connector card, and updating the Edge Function secret in Supabase, are separate steps. If you rotated a key in Stripe, Resend, or Twilio and Rocket fails to push the new value, use the steps above so your Edge Functions keep working.
</Note>

## Call your function from the app [#call-your-function-from-the-app]

Once deployed, Rocket can automatically wire your function into your app.
You can also ask for specific triggers, such as:

- After user actions like signups or button clicks.
- From other backend processes.

To test first, ask Rocket to add a test button that triggers the function safely during development.

## Example: Send a welcome email [#example-send-a-welcome-email]

**Prompt:**

```plaintext wrap
Send a welcome email using Resend when a new user signs up.
```

**Rocket will:**
- Generate the function.
- Request the `RESEND_API_KEY`.
- Show a **Push to Supabase** popup.
- Connect the function to your signup flow.

## Troubleshooting [#troubleshooting]

### 1. Function not found [#1-function-not-found]

<Info>
  <b>What you will see:</b>
  Rocket or your app reports that the function does not exist.
</Info>

To fix this:

<Steps>

  <Step title="Click Fix it">
    Rocket shows an error popup with a **Fix it** button. Click it. Rocket will check the issue and either:
    - Repair the function and show a **Push to Supabase** popup.
    - Generate a script to deploy if schema changes are needed.
  </Step>

  <Step title="Describe unexpected behavior">
    If the function exists but does not behave as expected, describe the problem clearly in chat. For example:

    ```plaintext wrap
    When users sign up, they are not receiving the welcome email.
    ```

    Rocket will inspect, apply changes, and prompt you to redeploy.
  </Step>

</Steps>

### 2. Push to Supabase failed [#2-push-to-supabase-failed]

<Info>
  <b>What you will see:</b>
  An error appears when you click **Push to Supabase**.
</Info>

To fix this:

<Steps>

  <Step title="Review the error message">
    Check the error message shown in the popup.
  </Step>

  <Step title="Click Fix it">
    If a **Fix it** button is available, click it. Rocket will:
    - Fix the function.
    - Show a new **Push to Supabase** popup so you can retry.
  </Step>

  <Step title="Push the updated function">
    Push the updated function or script as prompted.
  </Step>

</Steps>

### 3. Secret or API key update failed [#3-secret-or-api-key-update-failed]

<Info>
  <b>What you will see:</b>
  Rocket cannot save or update a secret, or an Edge Function fails after you rotate a Stripe, Resend, or Twilio key.
</Info>

To fix this:

1. Confirm the new key works in the provider dashboard (Stripe, Resend, or Twilio).
2. [Update the secret manually in Supabase](#update-a-secret-manually-in-supabase).
3. Retry the action that calls the Edge Function.

If the secret name in Supabase does not match what the function reads (for example, `RESEND_API_KEY`), add or rename the secret so the names match, then save again.

<Card icon="server" horizontal title="Backend logic, deployed in minutes">
  Your Rocket app now runs secure server logic with Supabase Edge Functions, all created and deployed from chat.
</Card>

---

## What's next? [#whats-next]

<CardGroup cols={2}>
  <Card title="Storage buckets" icon="folder" href="/build/connectors/supabase/storage-buckets">
    Set up file uploads and media storage with Supabase Storage.
  </Card>
  <Card title="Supabase overview" icon="database" href="/build/connectors/supabase/overview">
    See all Supabase features available in Rocket.
  </Card>
</CardGroup>
