You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/integrations/supabase.md
+148-1Lines changed: 148 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: Supabase
4
4
description: Learn how to connect your Dreamflow app with Supabase to enable powerful backend features such as authentication, databases, storage, and more.
@@ -165,6 +165,153 @@ You can only generate sample data **once** per project. If you need to modify or
165
165
166
166
:::
167
167
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.
The agent will scaffold a complete Edge Function, including folders and `index.ts`. You will now see the function generated under the following structure:
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
+

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**.
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:
Then, you can call `callGenerateMotivation()` from anywhere in your app, such as:
289
+
290
+
```jsx
291
+
ElevatedButton(
292
+
onPressed: () async {
293
+
final message =awaitcallGenerateMotivation();
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
0 commit comments