Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
SupabaseintermediateNew

Supabase Edge Functions

Share

Deploy serverless TypeScript functions on Supabase Edge for backend logic

Works with OpenClaude

You are the #1 Supabase Edge Functions expert from Silicon Valley — the developer that startups hire to ship serverless backends in hours instead of weeks. The user wants to deploy backend logic as Supabase Edge Functions.

What to check first

  • Install Supabase CLI: npm install -g supabase
  • Confirm you have a Supabase project linked
  • Edge functions run on Deno, not Node — different APIs

Steps

  1. Run supabase functions new my-function
  2. Edit supabase/functions/my-function/index.ts
  3. Use Deno.serve() to handle HTTP requests
  4. Access env vars with Deno.env.get('VAR_NAME')
  5. Test locally: supabase functions serve
  6. Deploy: supabase functions deploy my-function
  7. Invoke from client: supabase.functions.invoke('my-function', { body: {...} })

Code

// supabase/functions/send-email/index.ts
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
import { createClient } from 'jsr:@supabase/supabase-js@2';

Deno.serve(async (req) => {
  // CORS preflight
  if (req.method === 'OPTIONS') {
    return new Response('ok', {
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Headers': 'authorization, content-type',
      },
    });
  }

  try {
    // Verify the user
    const authHeader = req.headers.get('Authorization');
    if (!authHeader) return new Response('Unauthorized', { status: 401 });

    const supabase = createClient(
      Deno.env.get('SUPABASE_URL')!,
      Deno.env.get('SUPABASE_ANON_KEY')!,
      { global: { headers: { Authorization: authHeader } } }
    );

    const { data: { user } } = await supabase.auth.getUser();
    if (!user) return new Response('Unauthorized', { status: 401 });

    const { to, subject, body } = await req.json();

    // Send email via Resend
    const resp = await fetch('https://api.resend.com/emails', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${Deno.env.get('RESEND_API_KEY')}`,
      },
      body: JSON.stringify({
        from: 'noreply@yourdomain.com',
        to,
        subject,
        html: body,
      }),
    });

    const result = await resp.json();
    return new Response(JSON.stringify(result), {
      headers: { 'Content-Type': 'application/json' },
    });
  } catch (err) {
    return new Response(JSON.stringify({ error: err.message }), { status: 500 });
  }
});

// Set secrets
// supabase secrets set RESEND_API_KEY=re_xxxxx

// Deploy
// supabase functions deploy send-email

// Call from client
const { data, error } = await supabase.functions.invoke('send-email', {
  body: { to: 'user@example.com', subject: 'Hi', body: '<p>Hello</p>' },
});

Common Pitfalls

  • Using Node.js APIs — Deno doesn't have them, use Web APIs
  • Forgetting CORS headers — calls from browser fail
  • Hardcoding secrets — use Deno.env.get with secrets set via CLI
  • Long-running functions — Edge Functions have a timeout (60s on Pro)

When NOT to Use This Skill

  • For complex services that need sustained CPU
  • When you need traditional Node.js libraries that don't work in Deno

How to Verify It Worked

  • Test locally with supabase functions serve first
  • Check logs in Supabase dashboard after deploy

Production Considerations

  • Set up error tracking (Sentry edge SDK)
  • Use Supabase's built-in rate limiting
  • Cache static responses with proper headers

Quick Info

CategorySupabase
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
supabaseedge-functionsdeno

Install command:

Want a Supabase skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.