Skip to content
Every tutorial here is 100% free — and always will be
LSLovableStudent

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

Website made, maintained and hosted by PromptSites.com

PromptSites logo