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
const supabaseClient = createClient(
Deno.env.get('SUPABASE_URL') ?? '',
Deno.env.get('SUPABASE_ANON_KEY') ?? ''
)
// create a stripe client
const stripe = Stripe(Deno.env.get('STRIPE_SECRET_KEY'))
// Get the authorization header from the request.
const authHeader = req.headers.get('Authorization').replace("Bearer ","")
// Client now respects auth policies for this user
supabaseClient.auth.setAuth(authHeader)
// set the user profile
const user = supabase.auth.user()
// 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 })
}
})