Instant deployment
Deploy Edge Functions in seconds
Global
Deployed to 29 regions worldwide
Typescript ready
TypeScript, WASM, ES Modules
Database webhooks
Invoke Edge Functions based on any event in your database
Anatomy of an Edge Function
Asynchronous tasks within minutes using Supabase Functions with simple authenticated access to the rest of the Supabase Ecosystem.
import { serve } from 'https://deno.land/std@0.131.0/http/server.ts'
import Stripe from 'https://esm.sh/stripe?target=deno&no-check'
import { Customer } from 'types'
serve(async (req) => {
try {
// create a supabase client with Auth context of the user that called the function
const supabaseClient = createClient(
Deno.env.get('SUPABASE_URL') ?? '',
Deno.env.get('SUPABASE_ANON_KEY') ?? '',
{ global: { headers: { Authorization: req.headers.get('Authorization')! } } }
)
// create a stripe client
const stripe = Stripe(Deno.env.get('STRIPE_SECRET_KEY'))
// get the current logged in user
const {data: { user },} = supabase.auth.getUser()
// Retrieve user metadata that only the user is allowed to select
const { data, error } = await supabaseClient
.from<Customer>('user_profiles')
.select('address, tax, billing_email, phone')
if (error) throw error
const customer = await stripe.customers.create({
description: 'My First Stripe Customer (created by a Supabase edge function)',
phone: data.phone,
address: data.address,
email: user.email,
})
return new Response(JSON.stringify(customer), { status: 200 })
} catch (error) {
return new Response(JSON.stringify(error), { status: 400 })
}
})