Skip to content

Commit d3890b9

Browse files
committed
Add Supabase Edge Functions Docs
1 parent 6372013 commit d3890b9

File tree

7 files changed

+148
-1
lines changed

7 files changed

+148
-1
lines changed
64.8 KB
Binary file not shown.
226 KB
Binary file not shown.
172 KB
Binary file not shown.
97.2 KB
Binary file not shown.
67.2 KB
Binary file not shown.
52.3 KB
Binary file not shown.

docs/integrations/supabase.md

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Supabase
44
description: Learn how to connect your Dreamflow app with Supabase to enable powerful backend features such as authentication, databases, storage, and more.
55
tags: [Supabase, Integration, Dreamflow, Backend]
66
sidebar_position: 2
7-
toc_max_heading_level: 4
7+
toc_max_heading_level: 3
88
keywords: [Supabase, Integration, Dreamflow, Backend]
99
---
1010

@@ -165,6 +165,153 @@ You can only generate sample data **once** per project. If you need to modify or
165165

166166
:::
167167

168+
## Edge Functions
169+
170+
[Supabase Edge Functions](https://supabase.com/docs/guides/functions) let you run secure, server-side code without needing your own backend. These functions are perfect for tasks that require backend logic, secret handling, or integrations with external APIs such as OpenAI. Because they run on Supabase’s global edge network, they are fast, scalable, and isolated from your client code.
171+
172+
Edge Functions are ideal for:
173+
174+
- **Calling external APIs securely** (e.g., Stripe, Twilio, OpenAI) without exposing keys in the client app
175+
- **Generating personalized AI content** such as product recommendations, support replies, onboarding guides, weekly usage summaries, or tailored learning suggestions
176+
- **Running scheduled or on-demand automations**
177+
- **Performing complex business logic** thatt is not suitable for client-side execution
178+
- **Enforcing secure access rules** using Supabase Auth (require logged-in user)
179+
180+
:::info
181+
You can find [**more examples**](https://supabase.com/docs/guides/functions#examples) in the official documentation.
182+
:::
183+
184+
### Create and Deploy
185+
186+
Dreamflow provides a built-in workflow to generate, edit, configure, and deploy Supabase Edge Functions directly from your project — no command line needed.
187+
188+
To create and deploy the Edge Function, follow these steps:
189+
190+
#### 1. Create a New Edge Function
191+
192+
1. Open the **Supabase module** from the left sidebar.
193+
2. Scroll to **Edge Functions** and click **+** to create a new one.
194+
3. This opens the **Agent Panel** on the right with a prefilled starter prompt. Simply continue describing what you want your function to do. For example:
195+
196+
```jsx
197+
//Agent Prompt
198+
Create a Supabase Edge Function that uses OpenAI api to generate a motivational message based on the users habit progress.
199+
```
200+
201+
![create-edge-functions.avif](imgs/create-edge-functions.avif)
202+
203+
The agent will scaffold a complete Edge Function, including folders and `index.ts`. You will now see the function generated under the following structure:
204+
205+
![edge-function-file.avif](imgs/edge-function-file.avif)
206+
207+
:::info
208+
209+
You can open and edit the function like any other file in Dreamflow.
210+
211+
:::
212+
213+
#### 2. Add Required Secrets
214+
215+
If your Edge Functions require secrets like API keys, Dreamflow automatically detects them from your generated code and allows you to add the required values.
216+
217+
To configure your function’s secrets, open the **Supabase > Secrets** section and add the following:
218+
219+
- **YOUR_API_KEY**: Enter your own API key.
220+
- **SUPABASE_URL**: Copy the **API URL** from the **Project Details** section at the top.
221+
- **SUPABASE_ANON_KEY**: Copy the **Anon Key** from the same **Project Details** section.
222+
223+
Once added, Dreamflow will rewrite the deployment environment so your function can access these secrets at runtime.
224+
225+
![add-secrect.avif](imgs/add-secrect.avif)
226+
227+
#### 3. Deploy the Function
228+
229+
After reviewing your function and adding secrets:
230+
231+
1. Return to **Supabase > Edge Functions** section.
232+
2. Click **Deploy Function**.
233+
3. A confirmation dialog appears; click **Deploy**.
234+
235+
![deploy-edge-funciton.avif](imgs/deploy-edge-funciton.avif)
236+
237+
238+
#### 4. Verify Deployment
239+
240+
After deployment, open the **Supabase Dashboard > Edge Functions** page. You should now see your function listed.
241+
242+
![sb-edge-functions.avif](imgs/sb-edge-functions.avif)
243+
244+
245+
#### 5. Run or Test Your Edge Function
246+
247+
Once your Edge Function is deployed, you can trigger it directly from your app.
248+
249+
**Using Agent**
250+
251+
You can simply ask the Agent to connect the function to the correct part of your UI. For example:
252+
253+
```jsx
254+
Call the `generate-motivation` Supabase Edge Function on the home page and display the returned message in the motivational message widget.
255+
```
256+
257+
The agent will automatically place the call in the appropriate widget, manage loading states, and update your UI.
258+
259+
**Add Manually**
260+
261+
If you prefer to call the function manually, here is the recommended method using the official [**supabase_flutter**](https://pub.dev/packages/supabase_flutter) package. Here’s an example code:
262+
263+
```jsx
264+
import 'package:supabase_flutter/supabase_flutter.dart';
265+
import 'dart:convert';
266+
267+
Future<String> callGenerateMotivation() async {
268+
final supabase = Supabase.instance.client;
269+
270+
final response = await supabase.functions.invoke(
271+
'generate-motivation',
272+
body: {
273+
'progress': 0.6,
274+
'completedHabits': 3,
275+
'totalHabits': 5,
276+
'userName': 'Mike',
277+
},
278+
);
279+
280+
if (response.data != null) {
281+
return response.data['message'] ?? 'No message returned.';
282+
} else {
283+
throw Exception('Failed: ${response.error?.message}');
284+
}
285+
}
286+
```
287+
288+
Then, you can call `callGenerateMotivation()` from anywhere in your app, such as:
289+
290+
```jsx
291+
ElevatedButton(
292+
onPressed: () async {
293+
final message = await callGenerateMotivation();
294+
print(message);
295+
},
296+
child: Text(message),
297+
)
298+
```
299+
300+
:::tip[Monitor Your Edge Function]
301+
302+
After deploying your Edge Function, you can view detailed insights directly from the **Supabase Dashboard**. Open your project in Supabase > **Edge Functions** > select your function. From there, you can:
303+
304+
- **View Invocations** (every time your app calls the function)
305+
- **Check Logs** for debugging and server output
306+
- **Function Code** to update and deploy code directly
307+
- **Deployment Details**
308+
309+
![sb-edge-functions-logs](imgs/sb-edge-functions-logs.avif)
310+
311+
This is extremely helpful for verifying that your function is running correctly and diagnosing any issues.
312+
313+
:::
314+
168315
## FAQs
169316
170317
<details>

0 commit comments

Comments
 (0)