Skip to content

Commit dadc4e5

Browse files
committed
Add warnings and FAQs
1 parent 766d8a0 commit dadc4e5

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

docs/integrations/supabase.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ Edge Functions are ideal for:
185185
You can find [**more examples**](https://supabase.com/docs/guides/functions#examples) in the official documentation.
186186
:::
187187

188+
:::warning
189+
Dreamflow doesn’t support running Edge Functions locally yet because the editor has no built-in terminal or local [**Deno**](https://deno.com/) runtime.
190+
:::
191+
188192
### Create and Deploy
189193

190194
Dreamflow provides a built-in workflow to generate, edit, configure, and deploy Supabase Edge Functions directly from your project — no command line needed.
@@ -398,6 +402,7 @@ const profile: ProfileRow = data[0]; // typed and validated
398402
399403
- **Use Shared Modules for Reusable Logic:** If multiple functions need the same utilities (like an OpenAI client, validators, or formatting helpers), place them inside `supabase/functions/_shared/`. This avoids code duplication and keeps each function focused only on its own task.
400404
- **Use `database.types.ts` for Strong Typing:** Generate and import `database.types.ts` to ensure all database queries inside edge functions match your actual schema. This provides autocomplete, prevents schema mismatches, and makes your functions safer and easier to maintain.
405+
- **Use Consistent Error Handling Patterns:** Implement clear and predictable error handling inside each Edge Function. Wrap risky operations in `try/catch`, log errors using `console.error()` so they appear in the Supabase Dashboard logs, and always return structured JSON error responses.
401406
402407
## FAQs
403408
@@ -493,4 +498,61 @@ It depends on whether the function **requires JWT verification**. If the “Veri
493498
494499
![supabase-edge-function-logged-in](imgs/supabase-edge-function-logged-in.avif)
495500
</p>
501+
</details>
502+
503+
<details>
504+
<summary>
505+
How do I access the logged-in user inside an Edge Function?
506+
</summary>
507+
508+
<p>
509+
When your app makes a request and the user is logged in, the user’s JWT is automatically included in the `Authorization` header. Inside your Edge Function, you can read this header and fetch the authenticated user like this:
510+
511+
```tsx
512+
const authHeader = req.headers.get("Authorization");
513+
const { data: user } = await supabase.auth.getUser(authHeader);
514+
```
515+
516+
The `user` will contain the full Supabase Auth user object. If the request has no token or an invalid token, `user` will be `null`.
517+
</p>
518+
</details>
519+
520+
<details>
521+
<summary>
522+
Why am I getting “Error: Function invocation timed out” and how do I fix it?
523+
</summary>
524+
525+
<p>
526+
527+
This error appears when your Edge Function takes too long to finish, often because it’s waiting on a slow external API call without a timeout. For example, a request like `await fetch("https://slow-api.example.com/report")` can hang indefinitely, causing the function to hit Supabase’s execution limit and fail.
528+
529+
To fix this, add a timeout using `AbortController`:
530+
531+
```tsx
532+
const controller = new AbortController();
533+
const timeout = setTimeout(() => controller.abort(), 5000); // 5s timeout
534+
535+
const response = await fetch("https://slow-api.example.com/report", {
536+
signal: controller.signal,
537+
}).finally(() => clearTimeout(timeout));
538+
```
539+
540+
Then return a clear error when the timeout occurs:
541+
542+
```tsx
543+
try {
544+
// fetch with timeout
545+
} catch (err) {
546+
if (err.name === "AbortError") {
547+
return new Response(
548+
JSON.stringify({ error: "Upstream service timed out" }),
549+
{ status: 504, headers: { "Content-Type": "application/json" } }
550+
);
551+
}
552+
}
553+
```
554+
555+
This prevents your function from hanging, ensures it fails cleanly, and avoids timeout errors in production.
556+
557+
</p>
496558
</details>

0 commit comments

Comments
 (0)