An Edge Function is a small piece of server code that runs when it is called, without a server you manage yourself. In a Supabase project, Edge Functions are written in TypeScript and run on Supabase's servers. Apps built with Lovable use them for anything the browser should not do on its own, such as calling a payment or AI service.
Why an app built without a server needs one
Most apps built with an AI app builder have no server of their own. The browser talks straight to the database, protected by Row Level Security, and that works well for reading and writing the app's own data. It does not work for anything that needs a secret, because everything in the browser is visible to the visitor.
An Edge Function fills that gap. The browser calls the function, the function does the part that needs a secret, and only the result goes back. Which keys can be in browser code lists the keys that need this treatment.
Where the secrets live
A function reads its keys from the project's secrets, set in the Supabase dashboard or from the command line, as described in the Supabase guide to function secrets. Lovable has its own secrets store for the same purpose. The key is never in the app's code, so it never reaches the browser and never ends up in version history.
Supabase also gives functions the project's own secret key by default. That key skips every access rule in the database, so a function that uses it has to do the checking itself.
The function must check who is calling
Moving a key into a function hides it, but it does not decide who may use it. A function that passes every request on to an AI service has only moved the problem: anyone can still run up the bill, now through the function. A function that writes to the database with the secret key and trusts an ID sent by the browser lets anyone write anywhere.
A sound function does three things before the real work:
- Requires a signed-in user, by reading the user from the session token the app sends, not from a value in the request body. Supabase's guide to securing functions shows how.
- Checks that this user may do this particular thing, such as act on their own records only.
- Limits how often each user may call it, when each call costs money.
What to check
For each function, ask what it does with a request that carries only the app's public key and no user, and with one where a signed-in user asks for someone else's data. If the answer is "it does it anyway", the function is a door with the key taped to it.