When should I use an Edge Function?
Last checked 31 Aug 2026
Short answer
Use one whenever your app needs a secret key, must call a third-party service, or needs logic that shouldn't be trusted to run in the user's browser.
The test to apply
Ask: "could a user with dev tools open and tamper with this, or see something they shouldn't?" If yes, it belongs in an edge function, not front-end code.
Clear cases for an edge function
- Calling any API that requires a secret key (payment providers, email senders, AI providers without Lovable AI, private REST APIs).
- Enforcing business rules that must not be bypassable — e.g. calculating a price server-side rather than trusting a value sent from the browser.
- Processing webhooks from external services (Stripe events, form submissions from a third party).
- Any action that should be logged, rate-limited or audited centrally.
Cases where you don't need one
- Reading/writing your own database tables directly, when RLS policies already enforce who can do what — the Supabase client can call the database straight from the front-end safely, provided RLS is correct.
- Pure UI logic and client-side state.
- Calling Lovable AI for simple in-app AI features, which is designed to be called without you managing your own provider keys.
A quick decision table
| Situation | Approach |
|---|---|
| Direct table read/write, RLS handles access | Call the database directly |
| Needs a third-party secret key | Edge function |
| Must run trusted server-side calculations | Edge function |
| Simple in-app AI feature | Lovable AI, often no separate function needed |
Add an edge function to validate the promo code and calculate the discounted total server-side, instead of trusting the discount sent from the browser
What usually goes wrong
- Overusing edge functions for things RLS already handles, adding unnecessary complexity and latency.
- Underusing them — trusting a price, quantity or role value sent straight from the client.
Related: /questions/what-are-supabase-edge-functions, /questions/how-do-i-safely-store-api-keys.
Sources
Was this answer helpful?
Related questions
- AnswerHow do I back up my Lovable database?Lovable Cloud stores backups you can restore from directly in the Database screen; for extra safety, also ask Lovable to export your data periodically.
- AnswerHow do I connect Supabase to Lovable?In your Lovable project, open the Supabase integration and authorise Lovable to connect to an existing Supabase project (or create a new one), then Lovable can read and write to it the same way it does with Lovable Cloud.
- AnswerHow do I safely store API keys?Store keys as secrets in your backend (Lovable Cloud/Supabase) and call the third-party API from a server/edge function — never put keys in front-end code.
- AnswerHow do I view my database data?Open the Cloud tab (or ask Lovable) to browse tables, edit rows and run SQL directly inside your project — no separate Supabase login needed.