0
Challenge · 73Services

Edge Functions: Deno, secrets & CORS

Functionsused in ~70% of apps

Server Actions cover almost everything in DevLog — but not "send a digest every Monday at 9am with no browser tab open," and not "receive a webhook from an email provider that isn't a Next.js route at all." That is what an Edge Function is for: a small, independently-deployed piece of server code, running on Deno instead of Node, that Supabase invokes for you. It looks like a tiny web server. It is actually a second front door into your database — and the two locks on that door are the entire concept.

Core idea. An Edge Function is a Deno 2 `Deno.serve()` handler that Supabase deploys close to the caller. Every request that reaches it passes two independent gates: the platform's `verify_jwt` (config.toml) asks "is there a valid user JWT at all?", and `@supabase/server`'s `auth` mode asks "whose privilege should my Postgres client carry?" A browser calling on behalf of a signed-in user wants both closed (`verify_jwt: true`, `auth: 'user'`). A cron job calling on the database's own behalf wants both open (`verify_jwt: false`, `auth: 'secret'`) — there is no user JWT to check, ever.
Playground, this isn't a screenshot
scenarioa signed-in visitor loads their own comments
1 / 6
fetch() from Next.js

Your Server Component calls the function with the caller's own JWT and the publishable key on `apikey`. Nothing privileged has happened yet.

Gate A (verify_jwt) and gate B (auth mode) are independent settings in two different files. The bug that ships is setting one for the browser case and forgetting to flip the other for the cron case — or vice versa.

↑ play a little first, then dig in